1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-19 04:20:27 +01:00

patch to add binary mode on opening files (for Windows+Cygwin compatibility).

This commit is contained in:
dan
2002-09-15 20:37:41 +00:00
parent 3fc803c0d8
commit 92b012e800
20 changed files with 41 additions and 34 deletions

View File

@@ -6,6 +6,8 @@ Changes since version 0.80.1:
the root menu (sent by "Marc-Christian Petersen" <m.c.p@wolk-project.de>) the root menu (sent by "Marc-Christian Petersen" <m.c.p@wolk-project.de>)
- Fixed dock's menu mapping position when dock is on the right side. - Fixed dock's menu mapping position when dock is on the right side.
- Map clip's menu so that it never gets out of screen on the left or the right. - Map clip's menu so that it never gets out of screen on the left or the right.
- Patch to add binary mode on opening files (needed for Windows with Cygwin)
(sent by luke <luke@posh.optushome.com.au>)
Changes since version 0.80.0: Changes since version 0.80.0:

View File

@@ -586,7 +586,7 @@ testText(WMScreen *scr)
{ {
WMWindow *win; WMWindow *win;
WMText *text; WMText *text;
FILE *file = fopen("wm.html", "r"); FILE *file = fopen("wm.html", "rb");
windowCount++; windowCount++;

View File

@@ -1593,7 +1593,7 @@ WMReadPropListFromFile(char *file)
struct stat stbuf; struct stat stbuf;
size_t length; size_t length;
f = fopen(file, "r"); f = fopen(file, "rb");
if (!f) { if (!f) {
/* let the user print the error message if he really needs to */ /* let the user print the error message if he really needs to */
/*wsyserror(_("could not open domain file '%s' for reading"), file);*/ /*wsyserror(_("could not open domain file '%s' for reading"), file);*/
@@ -1672,7 +1672,7 @@ WMWritePropListToFile(WMPropList *plist, char *path, Bool atomically)
mask = umask(0); mask = umask(0);
umask(mask); umask(mask);
fchmod(fd, 0644 & ~mask); fchmod(fd, 0644 & ~mask);
if ((theFile = fdopen(fd, "w")) == NULL) { if ((theFile = fdopen(fd, "wb")) == NULL) {
close(fd); close(fd);
} }
#else #else

View File

@@ -282,6 +282,10 @@ enum {
#define M_PI 3.14159265358979323846 #define M_PI 3.14159265358979323846
#endif #endif
/* Silly hack for Windows systems with cygwin */
#ifndef O_BINARY
# define O_BINARY 0
#endif
static int fetchFile(char* toPath, char *imageSrcFile, static int fetchFile(char* toPath, char *imageSrcFile,
char *imageDestFileName); char *imageDestFileName);
@@ -302,9 +306,9 @@ static WMPoint magnifyInitialize(W_ColorPanel *panel);
static void magnifyPutCursor(WMWidget *w, void *data); static void magnifyPutCursor(WMWidget *w, void *data);
static Pixmap magnifyCreatePixmap(WMColorPanel *panel); static Pixmap magnifyCreatePixmap(WMColorPanel *panel);
static void magnifyGetImageStored(W_ColorPanel *panel, int x1, int y1, static void magnifyGetImageStored(W_ColorPanel *panel, int x1, int y1,
int x2, int y2); int x2, int y2);
static XImage* magnifyGetImage(WMScreen *scr, XImage *image, int x, int y, static XImage* magnifyGetImage(WMScreen *scr, XImage *image, int x, int y,
int w, int h); int w, int h);
static wheelMatrix* wheelCreateMatrix(unsigned int width , unsigned int height); static wheelMatrix* wheelCreateMatrix(unsigned int width , unsigned int height);
static void wheelDestroyMatrix(wheelMatrix *matrix); static void wheelDestroyMatrix(wheelMatrix *matrix);
@@ -1282,7 +1286,7 @@ readXColors(W_ColorPanel *panel)
return; return;
} }
else { else {
if ((rgbtxt = fopen(RGBTXT, "r"))) { if ((rgbtxt = fopen(RGBTXT, "rb"))) {
while (fgets(line, MAX_LENGTH, rgbtxt)) { while (fgets(line, MAX_LENGTH, rgbtxt)) {
if (sscanf(line, "%d%d%d %[^\n]", &red, &green, &blue, name)) { if (sscanf(line, "%d%d%d %[^\n]", &red, &green, &blue, name)) {
color = wmalloc(sizeof(RColor)); color = wmalloc(sizeof(RColor));
@@ -3644,13 +3648,13 @@ fetchFile(char *toPath, char *srcFile, char *destFile)
char *tmp; char *tmp;
char buf[BUFSIZE]; char buf[BUFSIZE];
if ((src = open(srcFile, O_RDONLY)) == 0) { if ((src = open(srcFile, O_RDONLY|O_BINARY)) == 0) {
wsyserror(_("Could not open %s"), srcFile); wsyserror(_("Could not open %s"), srcFile);
return -1; return -1;
} }
tmp = wstrconcat(toPath, destFile); tmp = wstrconcat(toPath, destFile);
if ((dest = open( tmp, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) if ((dest = open( tmp, O_RDWR|O_CREAT|O_BINARY, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH))
== 0) { == 0) {
wsyserror(_("Could not create %s"), tmp); wsyserror(_("Could not create %s"), tmp);
wfree(tmp); wfree(tmp);

View File

@@ -420,7 +420,7 @@ dumpRImage(char *path, RImage *image)
FILE *f; FILE *f;
int channels = (image->format == RRGBAFormat ? 4 : 3); int channels = (image->format == RRGBAFormat ? 4 : 3);
f = fopen(path, "w"); f = fopen(path, "wb");
if (!f) { if (!f) {
wsyserror(path); wsyserror(path);
return; return;
@@ -1352,7 +1352,7 @@ loadRImage(WMScreen *scr, char *path)
int w, h, d; int w, h, d;
Pixmap pixmap; Pixmap pixmap;
f = fopen(path, "r"); f = fopen(path, "rb");
if (!f) if (!f)
return None; return None;

View File

@@ -701,9 +701,9 @@ storeCommandInScript(char *cmd, char *line)
path = wstrconcat(wusergnusteppath(), "/Library/WindowMaker/autostart"); path = wstrconcat(wusergnusteppath(), "/Library/WindowMaker/autostart");
f = fopen(path, "r"); f = fopen(path, "rb");
if (!f) { if (!f) {
f = fopen(path, "w"); f = fopen(path, "wb");
if (!f) { if (!f) {
wsyserror(_("could not create %s"), path); wsyserror(_("could not create %s"), path);
goto end; goto end;
@@ -719,7 +719,7 @@ storeCommandInScript(char *cmd, char *line)
tmppath = wstrconcat(wusergnusteppath(), tmppath = wstrconcat(wusergnusteppath(),
"/Library/WindowMaker/autostart.tmp"); "/Library/WindowMaker/autostart.tmp");
fo = fopen(tmppath, "w"); fo = fopen(tmppath, "wb");
if (!fo) { if (!fo) {
wsyserror(_("could not create temporary file %s"), tmppath); wsyserror(_("could not create temporary file %s"), tmppath);
wfree(tmppath); wfree(tmppath);

View File

@@ -1739,7 +1739,7 @@ connectKFM(WScreen *scr)
wfree(buffer); wfree(buffer);
/* pid file */ /* pid file */
f = fopen(path, "r"); f = fopen(path, "rb");
wfree(path); wfree(path);
if (!f) if (!f)
return -1; return -1;
@@ -1771,7 +1771,7 @@ connectKFM(WScreen *scr)
} }
path = wstrconcat(wgethomedir(), "/.kde/share/apps/kfm/magic"); path = wstrconcat(wgethomedir(), "/.kde/share/apps/kfm/magic");
f = fopen(path, "r"); f = fopen(path, "rb");
wfree(path); wfree(path);
if (!f) { if (!f) {
return -1; return -1;

View File

@@ -202,7 +202,7 @@ static WRootMenuData *text_openMenuFile(char *path)
data = wmalloc(sizeof(TextMenuReaderData)); data = wmalloc(sizeof(TextMenuReaderData));
data->reader = TextMenuReader; data->reader = TextMenuReader;
data->file = fopen(path, "r"); data->file = fopen(path, "rb");
if (!data->file) { if (!data->file) {
return NULL; return NULL;

View File

@@ -1207,7 +1207,7 @@ readMenuFile(WScreen *scr, char *file_name)
#endif /* USECPP */ #endif /* USECPP */
if (!file) { if (!file) {
file = fopen(file_name, "r"); file = fopen(file_name, "rb");
if (!file) { if (!file) {
wsyserror(_("%s:could not open menu file"), file_name); wsyserror(_("%s:could not open menu file"), file_name);
return NULL; return NULL;
@@ -1309,7 +1309,7 @@ readMenuPipe(WScreen *scr, char **file_name)
#endif /* USECPP */ #endif /* USECPP */
if (!file) { if (!file) {
file = popen(filename, "r"); file = popen(filename, "rb");
if (!file) { if (!file) {
wsyserror(_("%s:could not open menu file"), filename); wsyserror(_("%s:could not open menu file"), filename);

View File

@@ -492,7 +492,7 @@ loadData(WScreen *scr)
RImage *image; RImage *image;
Pixmap d[12]; Pixmap d[12];
f = fopen(PKGDATADIR"/xtree.dat", "r"); f = fopen(PKGDATADIR"/xtree.dat", "rb");
if (!f) if (!f)
return False; return False;

View File

@@ -15,10 +15,7 @@ INCLUDES = $(DFLAGS) -I$(top_srcdir)/WINGs -I$(top_srcdir)/wrlib \
@HEADER_SEARCH_PATH@ \ @HEADER_SEARCH_PATH@ \
-DETCDIR=\"sysconfdir\" -DDATADIR=\"pkgdatadir\" -DETCDIR=\"sysconfdir\" -DDATADIR=\"pkgdatadir\"
# X_EXTRA_LIBS is for libproplist in systems that need -lsocket liblist= @LIBRARY_SEARCH_PATH@ @INTLIBS@
# remove after we require lPL 0.10.2 which automatically resolves its
# library dependancies using the libPropList.la file
liblist= @LIBRARY_SEARCH_PATH@ @X_EXTRA_LIBS@ @INTLIBS@
wdwrite_LDADD = $(top_builddir)/WINGs/libWUtil.a $(liblist) wdwrite_LDADD = $(top_builddir)/WINGs/libWUtil.a $(liblist)

View File

@@ -133,7 +133,7 @@ LoadJPEG(RContext *rc, char *file_name, int *width, int *height)
if (!canLoad(rc)) if (!canLoad(rc))
return None; return None;
file = fopen(file_name, "r"); file = fopen(file_name, "rb");
if (!file) { if (!file) {
return None; return None;
} }

View File

@@ -595,7 +595,7 @@ readBlackBoxStyle(char *path)
char buffer[128], char token[128]; char buffer[128], char token[128];
WMPropList *style, *p; WMPropList *style, *p;
f = fopen(path, "r"); f = fopen(path, "rb");
if (!f) { if (!f) {
perror(path); perror(path);
return NULL; return NULL;

View File

@@ -296,7 +296,7 @@ Bool copyAllFiles(char *gsdir)
sprintf(path, "%s/USER_FILES", DATADIR); sprintf(path, "%s/USER_FILES", DATADIR);
f = fopen(path, "r"); f = fopen(path, "rb");
while (!feof(f)) { while (!feof(f)) {
if (!fgets(file, 255, f)) { if (!fgets(file, 255, f)) {
break; break;
@@ -319,7 +319,7 @@ Bool copyAllFiles(char *gsdir)
sprintf(path, "%s/USER_FILES", ETCDIR); sprintf(path, "%s/USER_FILES", ETCDIR);
f = fopen(path, "r"); f = fopen(path, "rb");
while (!feof(f)) { while (!feof(f)) {
if (!fgets(path, 255, f)) { if (!fgets(path, 255, f)) {
break; break;

View File

@@ -120,7 +120,7 @@ main(int argc, char **argv)
} }
} }
if (filename) { if (filename) {
file = fopen(filename, "r"); file = fopen(filename, "rb");
if (!file) { if (!file) {
char line[1024]; char line[1024];
sprintf(line, "%s: could not open \"%s\"", argv[0], filename); sprintf(line, "%s: could not open \"%s\"", argv[0], filename);

View File

@@ -109,7 +109,7 @@ RLoadJPEG(RContext *context, char *file_name, int index)
*/ */
struct my_error_mgr jerr; struct my_error_mgr jerr;
file = fopen(file_name, "r"); file = fopen(file_name, "rb");
if (!file) { if (!file) {
RErrorCode = RERR_OPEN; RErrorCode = RERR_OPEN;
return NULL; return NULL;

View File

@@ -37,6 +37,10 @@
#include "wraster.h" #include "wraster.h"
/* Silly hack for Windows systems with cygwin */
#ifndef O_BINARY
# define O_BINARY 0
#endif
typedef struct RCachedImage { typedef struct RCachedImage {
RImage *image; RImage *image;
@@ -321,7 +325,7 @@ identFile(char *path)
assert(path!=NULL); assert(path!=NULL);
fd = open(path, O_RDONLY); fd = open(path, O_RDONLY|O_BINARY);
if (fd < 0) { if (fd < 0) {
RErrorCode = RERR_OPEN; RErrorCode = RERR_OPEN;
return IM_ERROR; return IM_ERROR;

View File

@@ -245,7 +245,7 @@ RLoadXPM(RContext *context, char *file, int index)
int w, h, ccount, csize; int w, h, ccount, csize;
FILE *f; FILE *f;
f = fopen(file, "r"); f = fopen(file, "rb");
if (!f) { if (!f) {
RErrorCode = RERR_OPEN; RErrorCode = RERR_OPEN;
return NULL; return NULL;
@@ -569,7 +569,7 @@ RSaveXPM(RImage *image, char *filename)
char transp[16]; char transp[16];
char buf[128]; char buf[128];
file = fopen(filename, "w+"); file = fopen(filename, "wb+");
if (!file) { if (!file) {
RErrorCode = RERR_OPEN; RErrorCode = RERR_OPEN;
return False; return False;

View File

@@ -67,7 +67,7 @@ RLoadPNG(RContext *context, char *file, int index)
png_bytep *png_rows; png_bytep *png_rows;
unsigned char *ptr; unsigned char *ptr;
f = fopen(file, "r"); f = fopen(file, "rb");
if (!f) { if (!f) {
RErrorCode = RERR_OPEN; RErrorCode = RERR_OPEN;
return NULL; return NULL;

View File

@@ -127,7 +127,7 @@ RLoadPPM(RContext *context, char *file_name, int index)
#define GETL() if (!fgets(buffer, 255, file)) goto short_file #define GETL() if (!fgets(buffer, 255, file)) goto short_file
file = fopen(file_name, "r"); file = fopen(file_name, "rb");
if (!file) { if (!file) {
RErrorCode = RERR_OPEN; RErrorCode = RERR_OPEN;
return NULL; return NULL;