summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Fl_SVG_Image.cxx9
-rw-r--r--src/drivers/WinAPI/Fl_WinAPI_System_Driver.H1
-rw-r--r--src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx7
-rw-r--r--src/fl_utf8.cxx24
4 files changed, 32 insertions, 9 deletions
diff --git a/src/Fl_SVG_Image.cxx b/src/Fl_SVG_Image.cxx
index 0b29b8c48..3c8957afd 100644
--- a/src/Fl_SVG_Image.cxx
+++ b/src/Fl_SVG_Image.cxx
@@ -28,9 +28,6 @@
#include <stdlib.h>
#if defined(HAVE_LIBZ)
#include <zlib.h>
-# ifdef _WIN32
-# include <fcntl.h>
-# endif
#endif
#if !defined(HAVE_LONG_LONG)
@@ -82,11 +79,7 @@ float Fl_SVG_Image::svg_scaling_(int W, int H) {
/** Opens for reading a potentially gzip'ed file identified by a UTF-8 encoded filename. */
void* Fl_SVG_Image::fl_gzopen(const char *fname) {
#if defined(HAVE_LIBZ)
- int flags = 0;
-# ifdef _WIN32
- flags = _O_BINARY;
-# endif
- int fd = fl_open(fname, flags);
+ int fd = fl_open_ext(fname, 0, 0);
if (fd < 0) return NULL;
return gzdopen(fd, "r");
#else
diff --git a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H
index 43e0f54e2..fdc686fed 100644
--- a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H
+++ b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H
@@ -50,6 +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 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 efbe65d01..aa1ff7e50 100644
--- a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx
+++ b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx
@@ -42,6 +42,7 @@ typedef RPC_STATUS (WINAPI* uuid_func)(UUID __RPC_FAR *Uuid);
#include <time.h>
#include <direct.h>
#include <io.h>
+#include <fcntl.h>
// Apparently Borland C++ defines DIRECTORY in <direct.h>, which
// interfers with the Fl_File_Icon enumeration of the same name.
# ifdef DIRECTORY
@@ -136,6 +137,12 @@ 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) {
+ if (oflags == 0) oflags = _O_RDONLY;
+ oflags |= (translation ? _O_TEXT : _O_BINARY);
+ return this->open(f, oflags, pmode);
+}
+
FILE *Fl_WinAPI_System_Driver::fopen(const char* f, const char *mode) {
size_t l = strlen(f);
unsigned wn = fl_utf8toUtf16(f, (unsigned) l, NULL, 0) + 1; // Query length
diff --git a/src/fl_utf8.cxx b/src/fl_utf8.cxx
index b7d58eecd..afd5c6005 100644
--- a/src/fl_utf8.cxx
+++ b/src/fl_utf8.cxx
@@ -309,7 +309,7 @@ char *fl_getenv(const char* v) {
\param f the UTF-8 encoded filename
\param oflags other arguments are as in the standard open() function
\return a file descriptor upon successful completion, or -1 in case of error.
- \sa fl_fopen().
+ \sa fl_fopen(), fl_open_ext().
*/
int fl_open(const char* f, int oflags, ...)
{
@@ -321,6 +321,28 @@ int fl_open(const char* f, int oflags, ...)
return Fl::system_driver()->open(f, oflags, pmode);
}
+/** Cross-platform function to open files with a UTF-8 encoded name.
+ In comparison with fl_open(), this function allows to control whether
+ the file is opened in binary (a.k.a. untranslated) mode. This is especially
+ useful under the MSWindows 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 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 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);
+}
+
/** Cross-platform function to open files with a UTF-8 encoded name.