From 92b012e800e7270f8762e08175ca697642eb786d Mon Sep 17 00:00:00 2001 From: dan Date: Sun, 15 Sep 2002 20:37:41 +0000 Subject: [PATCH] patch to add binary mode on opening files (for Windows+Cygwin compatibility). --- ChangeLog | 2 ++ WINGs/Tests/wtest.c | 2 +- WINGs/proplist.c | 4 ++-- WINGs/wcolorpanel.c | 14 +++++++++----- WPrefs.app/Appearance.c | 4 ++-- WPrefs.app/MouseSettings.c | 6 +++--- src/kwm.c | 4 ++-- src/menureader.c | 2 +- src/rootmenu.c | 4 ++-- src/superfluous.c | 2 +- util/Makefile.am | 5 +---- util/directjpeg.c | 2 +- util/setstyle.c | 2 +- util/wmsetup.c | 4 ++-- util/wxcopy.c | 2 +- wrlib/jpeg.c | 2 +- wrlib/load.c | 6 +++++- wrlib/nxpm.c | 4 ++-- wrlib/png.c | 2 +- wrlib/ppm.c | 2 +- 20 files changed, 41 insertions(+), 34 deletions(-) diff --git a/ChangeLog b/ChangeLog index 88fbf159..4b661887 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,8 @@ Changes since version 0.80.1: the root menu (sent by "Marc-Christian Petersen" ) - 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. +- Patch to add binary mode on opening files (needed for Windows with Cygwin) + (sent by luke ) Changes since version 0.80.0: diff --git a/WINGs/Tests/wtest.c b/WINGs/Tests/wtest.c index f91f1fde..128b9bc4 100644 --- a/WINGs/Tests/wtest.c +++ b/WINGs/Tests/wtest.c @@ -586,7 +586,7 @@ testText(WMScreen *scr) { WMWindow *win; WMText *text; - FILE *file = fopen("wm.html", "r"); + FILE *file = fopen("wm.html", "rb"); windowCount++; diff --git a/WINGs/proplist.c b/WINGs/proplist.c index dd760781..c26ebe91 100644 --- a/WINGs/proplist.c +++ b/WINGs/proplist.c @@ -1593,7 +1593,7 @@ WMReadPropListFromFile(char *file) struct stat stbuf; size_t length; - f = fopen(file, "r"); + f = fopen(file, "rb"); if (!f) { /* let the user print the error message if he really needs to */ /*wsyserror(_("could not open domain file '%s' for reading"), file);*/ @@ -1672,7 +1672,7 @@ WMWritePropListToFile(WMPropList *plist, char *path, Bool atomically) mask = umask(0); umask(mask); fchmod(fd, 0644 & ~mask); - if ((theFile = fdopen(fd, "w")) == NULL) { + if ((theFile = fdopen(fd, "wb")) == NULL) { close(fd); } #else diff --git a/WINGs/wcolorpanel.c b/WINGs/wcolorpanel.c index b51f6a52..92fb35d0 100644 --- a/WINGs/wcolorpanel.c +++ b/WINGs/wcolorpanel.c @@ -282,6 +282,10 @@ enum { #define M_PI 3.14159265358979323846 #endif +/* Silly hack for Windows systems with cygwin */ +#ifndef O_BINARY +# define O_BINARY 0 +#endif static int fetchFile(char* toPath, char *imageSrcFile, char *imageDestFileName); @@ -302,9 +306,9 @@ static WMPoint magnifyInitialize(W_ColorPanel *panel); static void magnifyPutCursor(WMWidget *w, void *data); static Pixmap magnifyCreatePixmap(WMColorPanel *panel); 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, - int w, int h); + int w, int h); static wheelMatrix* wheelCreateMatrix(unsigned int width , unsigned int height); static void wheelDestroyMatrix(wheelMatrix *matrix); @@ -1282,7 +1286,7 @@ readXColors(W_ColorPanel *panel) return; } else { - if ((rgbtxt = fopen(RGBTXT, "r"))) { + if ((rgbtxt = fopen(RGBTXT, "rb"))) { while (fgets(line, MAX_LENGTH, rgbtxt)) { if (sscanf(line, "%d%d%d %[^\n]", &red, &green, &blue, name)) { color = wmalloc(sizeof(RColor)); @@ -3644,13 +3648,13 @@ fetchFile(char *toPath, char *srcFile, char *destFile) char *tmp; 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); return -1; } 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) { wsyserror(_("Could not create %s"), tmp); wfree(tmp); diff --git a/WPrefs.app/Appearance.c b/WPrefs.app/Appearance.c index 890feb1c..fa9b9e81 100644 --- a/WPrefs.app/Appearance.c +++ b/WPrefs.app/Appearance.c @@ -420,7 +420,7 @@ dumpRImage(char *path, RImage *image) FILE *f; int channels = (image->format == RRGBAFormat ? 4 : 3); - f = fopen(path, "w"); + f = fopen(path, "wb"); if (!f) { wsyserror(path); return; @@ -1352,7 +1352,7 @@ loadRImage(WMScreen *scr, char *path) int w, h, d; Pixmap pixmap; - f = fopen(path, "r"); + f = fopen(path, "rb"); if (!f) return None; diff --git a/WPrefs.app/MouseSettings.c b/WPrefs.app/MouseSettings.c index 61c4b1e9..54839b97 100644 --- a/WPrefs.app/MouseSettings.c +++ b/WPrefs.app/MouseSettings.c @@ -701,9 +701,9 @@ storeCommandInScript(char *cmd, char *line) path = wstrconcat(wusergnusteppath(), "/Library/WindowMaker/autostart"); - f = fopen(path, "r"); + f = fopen(path, "rb"); if (!f) { - f = fopen(path, "w"); + f = fopen(path, "wb"); if (!f) { wsyserror(_("could not create %s"), path); goto end; @@ -719,7 +719,7 @@ storeCommandInScript(char *cmd, char *line) tmppath = wstrconcat(wusergnusteppath(), "/Library/WindowMaker/autostart.tmp"); - fo = fopen(tmppath, "w"); + fo = fopen(tmppath, "wb"); if (!fo) { wsyserror(_("could not create temporary file %s"), tmppath); wfree(tmppath); diff --git a/src/kwm.c b/src/kwm.c index 63c56b67..b25ab731 100644 --- a/src/kwm.c +++ b/src/kwm.c @@ -1739,7 +1739,7 @@ connectKFM(WScreen *scr) wfree(buffer); /* pid file */ - f = fopen(path, "r"); + f = fopen(path, "rb"); wfree(path); if (!f) return -1; @@ -1771,7 +1771,7 @@ connectKFM(WScreen *scr) } path = wstrconcat(wgethomedir(), "/.kde/share/apps/kfm/magic"); - f = fopen(path, "r"); + f = fopen(path, "rb"); wfree(path); if (!f) { return -1; diff --git a/src/menureader.c b/src/menureader.c index d5955c8b..a0d4aa21 100644 --- a/src/menureader.c +++ b/src/menureader.c @@ -202,7 +202,7 @@ static WRootMenuData *text_openMenuFile(char *path) data = wmalloc(sizeof(TextMenuReaderData)); data->reader = TextMenuReader; - data->file = fopen(path, "r"); + data->file = fopen(path, "rb"); if (!data->file) { return NULL; diff --git a/src/rootmenu.c b/src/rootmenu.c index 2f242174..3fb59704 100644 --- a/src/rootmenu.c +++ b/src/rootmenu.c @@ -1207,7 +1207,7 @@ readMenuFile(WScreen *scr, char *file_name) #endif /* USECPP */ if (!file) { - file = fopen(file_name, "r"); + file = fopen(file_name, "rb"); if (!file) { wsyserror(_("%s:could not open menu file"), file_name); return NULL; @@ -1309,7 +1309,7 @@ readMenuPipe(WScreen *scr, char **file_name) #endif /* USECPP */ if (!file) { - file = popen(filename, "r"); + file = popen(filename, "rb"); if (!file) { wsyserror(_("%s:could not open menu file"), filename); diff --git a/src/superfluous.c b/src/superfluous.c index 905f5b6d..2a94f368 100644 --- a/src/superfluous.c +++ b/src/superfluous.c @@ -492,7 +492,7 @@ loadData(WScreen *scr) RImage *image; Pixmap d[12]; - f = fopen(PKGDATADIR"/xtree.dat", "r"); + f = fopen(PKGDATADIR"/xtree.dat", "rb"); if (!f) return False; diff --git a/util/Makefile.am b/util/Makefile.am index 951dc156..01815e59 100644 --- a/util/Makefile.am +++ b/util/Makefile.am @@ -15,10 +15,7 @@ INCLUDES = $(DFLAGS) -I$(top_srcdir)/WINGs -I$(top_srcdir)/wrlib \ @HEADER_SEARCH_PATH@ \ -DETCDIR=\"sysconfdir\" -DDATADIR=\"pkgdatadir\" -# X_EXTRA_LIBS is for libproplist in systems that need -lsocket -# 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@ +liblist= @LIBRARY_SEARCH_PATH@ @INTLIBS@ wdwrite_LDADD = $(top_builddir)/WINGs/libWUtil.a $(liblist) diff --git a/util/directjpeg.c b/util/directjpeg.c index b91544b4..645b55a7 100644 --- a/util/directjpeg.c +++ b/util/directjpeg.c @@ -133,7 +133,7 @@ LoadJPEG(RContext *rc, char *file_name, int *width, int *height) if (!canLoad(rc)) return None; - file = fopen(file_name, "r"); + file = fopen(file_name, "rb"); if (!file) { return None; } diff --git a/util/setstyle.c b/util/setstyle.c index e1c0e035..57c92547 100644 --- a/util/setstyle.c +++ b/util/setstyle.c @@ -595,7 +595,7 @@ readBlackBoxStyle(char *path) char buffer[128], char token[128]; WMPropList *style, *p; - f = fopen(path, "r"); + f = fopen(path, "rb"); if (!f) { perror(path); return NULL; diff --git a/util/wmsetup.c b/util/wmsetup.c index b8c02340..d71d0d67 100644 --- a/util/wmsetup.c +++ b/util/wmsetup.c @@ -296,7 +296,7 @@ Bool copyAllFiles(char *gsdir) sprintf(path, "%s/USER_FILES", DATADIR); - f = fopen(path, "r"); + f = fopen(path, "rb"); while (!feof(f)) { if (!fgets(file, 255, f)) { break; @@ -319,7 +319,7 @@ Bool copyAllFiles(char *gsdir) sprintf(path, "%s/USER_FILES", ETCDIR); - f = fopen(path, "r"); + f = fopen(path, "rb"); while (!feof(f)) { if (!fgets(path, 255, f)) { break; diff --git a/util/wxcopy.c b/util/wxcopy.c index 9ba02c2f..c483d8a3 100644 --- a/util/wxcopy.c +++ b/util/wxcopy.c @@ -120,7 +120,7 @@ main(int argc, char **argv) } } if (filename) { - file = fopen(filename, "r"); + file = fopen(filename, "rb"); if (!file) { char line[1024]; sprintf(line, "%s: could not open \"%s\"", argv[0], filename); diff --git a/wrlib/jpeg.c b/wrlib/jpeg.c index 4b31520a..b1cef8bf 100644 --- a/wrlib/jpeg.c +++ b/wrlib/jpeg.c @@ -109,7 +109,7 @@ RLoadJPEG(RContext *context, char *file_name, int index) */ struct my_error_mgr jerr; - file = fopen(file_name, "r"); + file = fopen(file_name, "rb"); if (!file) { RErrorCode = RERR_OPEN; return NULL; diff --git a/wrlib/load.c b/wrlib/load.c index 8cb38d0b..509aa90d 100644 --- a/wrlib/load.c +++ b/wrlib/load.c @@ -37,6 +37,10 @@ #include "wraster.h" +/* Silly hack for Windows systems with cygwin */ +#ifndef O_BINARY +# define O_BINARY 0 +#endif typedef struct RCachedImage { RImage *image; @@ -321,7 +325,7 @@ identFile(char *path) assert(path!=NULL); - fd = open(path, O_RDONLY); + fd = open(path, O_RDONLY|O_BINARY); if (fd < 0) { RErrorCode = RERR_OPEN; return IM_ERROR; diff --git a/wrlib/nxpm.c b/wrlib/nxpm.c index d5822011..8fcfc10a 100644 --- a/wrlib/nxpm.c +++ b/wrlib/nxpm.c @@ -245,7 +245,7 @@ RLoadXPM(RContext *context, char *file, int index) int w, h, ccount, csize; FILE *f; - f = fopen(file, "r"); + f = fopen(file, "rb"); if (!f) { RErrorCode = RERR_OPEN; return NULL; @@ -569,7 +569,7 @@ RSaveXPM(RImage *image, char *filename) char transp[16]; char buf[128]; - file = fopen(filename, "w+"); + file = fopen(filename, "wb+"); if (!file) { RErrorCode = RERR_OPEN; return False; diff --git a/wrlib/png.c b/wrlib/png.c index 7271eccb..e814ee35 100644 --- a/wrlib/png.c +++ b/wrlib/png.c @@ -67,7 +67,7 @@ RLoadPNG(RContext *context, char *file, int index) png_bytep *png_rows; unsigned char *ptr; - f = fopen(file, "r"); + f = fopen(file, "rb"); if (!f) { RErrorCode = RERR_OPEN; return NULL; diff --git a/wrlib/ppm.c b/wrlib/ppm.c index b8d08aa4..1e2a381e 100644 --- a/wrlib/ppm.c +++ b/wrlib/ppm.c @@ -127,7 +127,7 @@ RLoadPPM(RContext *context, char *file_name, int index) #define GETL() if (!fgets(buffer, 255, file)) goto short_file - file = fopen(file_name, "r"); + file = fopen(file_name, "rb"); if (!file) { RErrorCode = RERR_OPEN; return NULL;