1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-18 12:00:31 +01:00

Switch file ops to stdio

- Does away with the O_BINARY abomination
- as a byproduct, plugs an fd leak in wcolorpanel.c:fetchFile()
- sprinkle some fsync()s to files that have been written to (this
  needs to be done everywhere)

+ fix brown paper bag thinko in configure.ac
This commit is contained in:
Tamas TEVESZ
2010-03-26 20:25:27 +01:00
committed by Carlos R. Mafra
parent ea4645bc09
commit 71aa4f2884
8 changed files with 108 additions and 62 deletions

View File

@@ -21,6 +21,7 @@
#include <config.h>
#include <errno.h>
#include <X11/Xlib.h>
#include <stdlib.h>
#include <stdio.h>
@@ -37,10 +38,9 @@
#include "wraster.h"
/* Silly hack for Windows systems with cygwin */
#ifndef O_BINARY
# define O_BINARY 0
#endif
#define RETRY( x ) do { \
x; \
} while (errno == EINTR);
typedef struct RCachedImage {
RImage *image;
@@ -299,22 +299,25 @@ char *RGetImageFileFormat(char *file)
static int identFile(char *path)
{
int fd;
FILE *file;
unsigned char buffer[32];
size_t nread;
assert(path != NULL);
fd = open(path, O_RDONLY | O_BINARY);
if (fd < 0) {
RETRY( file = fopen(path, "rb") )
if (file == NULL) {
RErrorCode = RERR_OPEN;
return IM_ERROR;
}
if (read(fd, buffer, 32) < 1) {
close(fd);
RETRY( nread = fread(buffer, 1, sizeof(buffer), file) )
if (nread < sizeof(buffer) || ferror(file)) {
RETRY( fclose(file) )
RErrorCode = RERR_READ;
return IM_ERROR;
}
close(fd);
RETRY( fclose(file) )
/* check for XPM */
if (strncmp((char *)buffer, "/* XPM */", 9) == 0)