[gegl] buffer: pass O_BINARY to g_open for binary files on windows



commit 7704eb1e97c23d496fd520f7e04bec14b4b52453
Author: Øyvind Kolås <pippin gimp org>
Date:   Mon Nov 18 18:26:21 2019 +0100

    buffer: pass O_BINARY to g_open for binary files on windows
    
    This adds the flag to all g_open calls that are for binary files,
    this fixes issue gimp#4235 - and other probably lurking issues
    in other APIs that have only been tested on linux.

 gegl/buffer/gegl-buffer-load.c             |  8 +++++++-
 gegl/buffer/gegl-buffer-save.c             | 10 ++++++++--
 gegl/buffer/gegl-tile-backend-file-async.c | 15 ++++++++++-----
 gegl/buffer/gegl-tile-backend-swap.c       | 14 +++++++-------
 4 files changed, 32 insertions(+), 15 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-load.c b/gegl/buffer/gegl-buffer-load.c
index 5455661a7..0d1a9a076 100644
--- a/gegl/buffer/gegl-buffer-load.c
+++ b/gegl/buffer/gegl-buffer-load.c
@@ -34,6 +34,12 @@
 #include <glib/gprintf.h>
 #include <glib/gstdio.h>
 
+#ifdef G_OS_WIN32
+#define BINARY_FLAG O_BINARY
+#else
+#define BINARY_FLAG 0
+#endif
+
 typedef struct
 {
   GeglBufferHeader header;
@@ -249,7 +255,7 @@ gegl_buffer_load (const gchar *path)
   LoadInfo *info = g_slice_new0 (LoadInfo);
 
   info->path = g_strdup (path);
-  info->i = g_open (info->path, O_RDONLY, 0770);
+  info->i = g_open (info->path, O_RDONLY|BINARY_FLAG, 0770);
   GEGL_NOTE (GEGL_DEBUG_BUFFER_LOAD, "starting to load buffer %s", path);
   if (info->i == -1)
     {
diff --git a/gegl/buffer/gegl-buffer-save.c b/gegl/buffer/gegl-buffer-save.c
index 8b5450eb2..667dfa638 100644
--- a/gegl/buffer/gegl-buffer-save.c
+++ b/gegl/buffer/gegl-buffer-save.c
@@ -37,6 +37,12 @@
 #include "gegl-tile.h"
 #include "gegl-buffer-index.h"
 
+#ifdef G_OS_WIN32
+#define BINARY_FLAG O_BINARY
+#else
+#define BINARY_FLAG 0
+#endif
+
 typedef struct
 {
   GeglBufferHeader header;
@@ -222,9 +228,9 @@ gegl_buffer_save (GeglBuffer          *buffer,
   info->path = g_strdup (path);
 
 #ifndef G_OS_WIN32
-  info->o    = g_open (info->path, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
+  info->o    = g_open (info->path, O_RDWR|O_CREAT|O_TRUNC|BINARY_FLAG, 
S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
 #else
-  info->o    = g_open (info->path, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);
+  info->o    = g_open (info->path, O_RDWR|O_CREAT|O_TRUNC|BINARY_FLAG, S_IRUSR|S_IWUSR);
 #endif
 
 
diff --git a/gegl/buffer/gegl-tile-backend-file-async.c b/gegl/buffer/gegl-tile-backend-file-async.c
index 215e5cb29..937c9a40d 100644
--- a/gegl/buffer/gegl-tile-backend-file-async.c
+++ b/gegl/buffer/gegl-tile-backend-file-async.c
@@ -63,6 +63,11 @@
 
 #endif
 
+#ifdef G_OS_WIN32
+#define BINARY_FLAG O_BINARY
+#else
+#define BINARY_FLAG 0
+#endif
 
 struct _GeglTileBackendFile
 {
@@ -1168,7 +1173,7 @@ gegl_tile_backend_file_constructed (GObject *object)
                         G_CALLBACK (gegl_tile_backend_file_file_changed),
                         self);
 
-      self->o = g_open (self->path, O_RDWR|O_CREAT, 0770);
+      self->o = g_open (self->path, O_RDWR|O_CREAT|BINARY_FLAG, 0770);
       if (self->o == -1)
         {
           /* Try again but this time with only read access. This is
@@ -1176,12 +1181,12 @@ gegl_tile_backend_file_constructed (GObject *object)
            * when it opens a GeglBuffer file in the source tree
            * (which is read-only).
            */
-          self->o = g_open (self->path, O_RDONLY, 0770);
+          self->o = g_open (self->path, O_RDONLY|BINARY_FLAG, 0770);
 
           if (self->o == -1)
             g_warning ("%s: Could not open '%s': %s", G_STRFUNC, self->path, g_strerror (errno));
         }
-      self->i = g_open (self->path, O_RDONLY, 0);
+      self->i = g_open (self->path, O_RDONLY|BINARY_FLAG, 0);
 
       self->header     = gegl_buffer_read_header (self->i, &offset)->header;
       self->header.rev = self->header.rev -1;
@@ -1234,7 +1239,7 @@ gegl_tile_backend_file_ensure_exist (GeglTileBackendFile *self)
 
       GEGL_NOTE (GEGL_DEBUG_TILE_BACKEND, "creating swapfile  %s", self->path);
 
-      self->o = g_open (self->path, O_RDWR|O_CREAT, 0770);
+      self->o = g_open (self->path, O_RDWR|O_CREAT|BINARY_FLAG, 0770);
       if (self->o == -1)
         g_warning ("%s: Could not open '%s': %s", G_STRFUNC, self->path, g_strerror (errno));
 
@@ -1248,7 +1253,7 @@ gegl_tile_backend_file_ensure_exist (GeglTileBackendFile *self)
                                backend->priv->px_size,
                                backend->priv->format);
       gegl_tile_backend_file_write_header (self);
-      self->i = g_open (self->path, O_RDONLY, 0);
+      self->i = g_open (self->path, O_RDONLY|BINARY_FLAG, 0);
 
       g_assert (self->i != -1);
       g_assert (self->o != -1);
diff --git a/gegl/buffer/gegl-tile-backend-swap.c b/gegl/buffer/gegl-tile-backend-swap.c
index 3e737dcca..9039f85c1 100644
--- a/gegl/buffer/gegl-tile-backend-swap.c
+++ b/gegl/buffer/gegl-tile-backend-swap.c
@@ -52,6 +52,11 @@
 
 #endif
 
+#ifdef G_OS_WIN32
+#define BINARY_FLAG O_BINARY
+#else
+#define BINARY_FLAG 0
+#endif
 
 /* maximal data size allowed to be pending in the swap queue at any given time,
  * as a factor of the maximal cache size.  when the amount of data in the queue
@@ -1431,13 +1436,8 @@ gegl_tile_backend_swap_ensure_exist (void)
 
       GEGL_NOTE (GEGL_DEBUG_TILE_BACKEND, "creating swapfile %s", path);
 
-#ifdef G_OS_WIN32
-      out_fd = g_open (path, O_RDWR|O_CREAT|O_BINARY, 0770);
-      in_fd = g_open (path, O_RDONLY|O_BINARY, 0);
-#else
-      out_fd = g_open (path, O_RDWR|O_CREAT, 0770);
-      in_fd = g_open (path, O_RDONLY, 0);
-#endif
+      out_fd = g_open (path, O_RDWR|O_CREAT|BINARY_FLAG, 0770);
+      in_fd = g_open (path, O_RDONLY|BINARY_FLAG, 0);
 
       if (out_fd == -1 || in_fd == -1)
         {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]