From f9cfe1378d6a98ea08f5dc412223b646deeabdaf Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Sun, 15 Oct 2017 12:34:24 +0000 Subject: [PATCH] Rename fl_open_ext() parameter 'translation' to 'binary'. The default (0) is 'text' mode, non-zero is 'binary' mode on platforms that distinguish text and binary mode. Currently Windows is the only supported platform that needs this. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12500 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- CHANGES | 2 +- FL/Fl_System_Driver.H | 7 ++++++- FL/fl_utf8.h | 2 +- src/Fl_SVG_Image.cxx | 2 +- src/drivers/WinAPI/Fl_WinAPI_System_Driver.H | 2 +- src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx | 4 ++-- src/fl_images_core.cxx | 2 +- src/fl_utf8.cxx | 8 ++++---- 8 files changed, 17 insertions(+), 12 deletions(-) diff --git a/CHANGES b/CHANGES index 24f53ad4b..9f27401e4 100644 --- a/CHANGES +++ b/CHANGES @@ -18,7 +18,7 @@ Changes in FLTK 1.4.0 Released: ??? ?? 2017 New Features and Extensions - (add new items here) - - New function: int fl_open_ext(const char* fname, int translation, int oflags, ...) + - New function: int fl_open_ext(const char* fname, int binary, int oflags, ...) to control the opening of files in binary/text mode in a cross-platform way. - New Fl_SVG_Image class: gives support of scalable vector graphics images to FLTK using the nanosvg software. diff --git a/FL/Fl_System_Driver.H b/FL/Fl_System_Driver.H index dfdd4c3e3..e49306a96 100644 --- a/FL/Fl_System_Driver.H +++ b/FL/Fl_System_Driver.H @@ -87,7 +87,12 @@ public: virtual char *getenv(const char* v) {return NULL;} virtual int putenv(char* v) {return -1;} virtual int open(const char* f, int oflags, int pmode) {return -1;} - virtual int open_ext(const char* f, int translation, int oflags, int pmode) {return this->open(f, oflags, pmode);} + + // Note: the default implementation ignores the 'binary' argument. + // Some platforms (notably Windows) may use this argument. + virtual int open_ext(const char* f, int binary, int oflags, int pmode) { + return this->open(f, oflags, pmode); + } virtual FILE *fopen(const char* f, const char *mode); virtual int system(const char* cmd) {return -1;} virtual int execvp(const char *file, char *const *argv) {return -1;} diff --git a/FL/fl_utf8.h b/FL/fl_utf8.h index 2b1623138..68ebf3f05 100644 --- a/FL/fl_utf8.h +++ b/FL/fl_utf8.h @@ -177,7 +177,7 @@ FL_EXPORT int fl_execvp(const char *file, char *const *argv); /* OD: Portable UTF-8 aware open wrapper */ FL_EXPORT int fl_open(const char* f, int o, ...); -FL_EXPORT int fl_open_ext(const char* fname, int translation, int oflags, ...); +FL_EXPORT int fl_open_ext(const char* fname, int binary, int oflags, ...); /* OD: Portable UTF-8 aware unlink wrapper */ FL_EXPORT int fl_unlink(const char *fname); diff --git a/src/Fl_SVG_Image.cxx b/src/Fl_SVG_Image.cxx index 45b0f74c4..d631e6a76 100644 --- a/src/Fl_SVG_Image.cxx +++ b/src/Fl_SVG_Image.cxx @@ -82,7 +82,7 @@ static char *svg_inflate(const char *fname) { struct stat b; fl_stat(fname, &b); long size = b.st_size; - int fd = fl_open_ext(fname, 0, 0); + int fd = fl_open_ext(fname, 1, 0); if (fd < 0) return NULL; gzFile gzf = gzdopen(fd, "r"); if (!gzf) return NULL; diff --git a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H index fdc686fed..6b3a1e85e 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H +++ b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H @@ -50,7 +50,7 @@ public: virtual char *getenv(const char* v); virtual int putenv(char* v) {return _putenv(v);} virtual int open(const char* f, int oflags, int pmode); - virtual int open_ext(const char* f, int translation, int oflags, int pmode); + virtual int open_ext(const char* f, int binary, int oflags, int pmode); virtual FILE *fopen(const char* f, const char *mode); virtual int system(const char* cmd); virtual int execvp(const char *file, char *const *argv); diff --git a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx index aa1ff7e50..806a76b22 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx +++ b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx @@ -137,9 +137,9 @@ int Fl_WinAPI_System_Driver::open(const char* f, int oflags, int pmode) { else return _wopen(wbuf, oflags, pmode); } -int Fl_WinAPI_System_Driver::open_ext(const char* f, int translation, int oflags, int pmode) { +int Fl_WinAPI_System_Driver::open_ext(const char* f, int binary, int oflags, int pmode) { if (oflags == 0) oflags = _O_RDONLY; - oflags |= (translation ? _O_TEXT : _O_BINARY); + oflags |= (binary ? _O_BINARY : _O_TEXT); return this->open(f, oflags, pmode); } diff --git a/src/fl_images_core.cxx b/src/fl_images_core.cxx index 0aa5bc49d..06930d17c 100644 --- a/src/fl_images_core.cxx +++ b/src/fl_images_core.cxx @@ -95,7 +95,7 @@ fl_check_images(const char *name, // I - Filename #ifdef FLTK_USE_NANOSVG # if defined(HAVE_LIBZ) if (header[0] == 0x1f && header[1] == 0x8b) { // denotes gzip'ed data - int fd = fl_open_ext(name, 0, 0); + int fd = fl_open_ext(name, 1, 0); if (fd < 0) return NULL; gzFile gzf = gzdopen(fd, "r"); if (gzf) { diff --git a/src/fl_utf8.cxx b/src/fl_utf8.cxx index de6a7ee54..60d7614d6 100644 --- a/src/fl_utf8.cxx +++ b/src/fl_utf8.cxx @@ -339,20 +339,20 @@ int fl_open(const char* f, int oflags, ...) useful on the Windows platform where files are by default opened in text (translated) mode. \param fname the UTF-8 encoded filename - \param translation if zero, the file is to be accessed in untranslated (a.k.a. binary) - mode. + \param binary if non-zero, the file is to be accessed in binary (a.k.a. + untranslated) mode. \param oflags,... these arguments are as in the standard open() function. Setting \p oflags to zero opens the file for reading. \return a file descriptor upon successful completion, or -1 in case of error. */ -int fl_open_ext(const char* fname, int translation, int oflags, ...) +int fl_open_ext(const char* fname, int binary, int oflags, ...) { int pmode; va_list ap; va_start(ap, oflags); pmode = va_arg (ap, int); va_end(ap); - return Fl::system_driver()->open_ext(fname, translation, oflags, pmode); + return Fl::system_driver()->open_ext(fname, binary, oflags, pmode); }