Hi

Here is my initial patch for GEGL to make gio an optional dependency for
those who run an already obsolete version of glib.

The only non-trivial part is GFileMonitor, and I actually scraped that
part.

Also another caveat is that I had to change the prototype of two
functions that wanted a GInputStream *. 

Any comment?

Hub

PS: there might also be some indent issues. Will fix them.
Index: configure.ac
===================================================================
--- configure.ac	(revision 2307)
+++ configure.ac	(working copy)
@@ -39,7 +39,7 @@
 
 # required versions of external libraries
 m4_define([babl_required_version], [0.0.20])
-m4_define([glib_required_version], [2.16.1])
+m4_define([glib_required_version], [2.12.0])
 m4_define([gtk_required_version], [2.8.6])
 m4_define([lua_required_version], [5.1.0])
 m4_define([cairo_required_version], [0.0.0])
@@ -434,7 +434,7 @@
 
 PKG_CHECK_MODULES(BABL, babl >= babl_required_version)
 
-GLIB_PACKAGES="gobject-2.0 gmodule-2.0 gio-2.0"
+GLIB_PACKAGES="gobject-2.0 gmodule-2.0 "
 AC_SUBST(GLIB_PACKAGES)
 
 dnl This PATH_GLIB is somewhat redundant, but does a sanity compile and 
@@ -453,6 +453,12 @@
         *** Errors follow:
             $DEP_PKG_ERRORS]))
 
+PKG_CHECK_MODULES(GIO, gio-2.0, 
+	have_gio="yes"
+	AC_DEFINE(HAVE_GIO, 1, [Define to 1 to compile with gio support.]),
+	have_gio="no (gio not found)")
+AM_CONDITIONAL(HAVE_GIO, test "x$have_gio" = "xyes")
+
 # Rerun PKG_CONFIG to add gthread-2.0 cflags and libs
 DEP_CFLAGS=`$PKG_CONFIG --cflags $GLIB_PACKAGES gthread-2.0`
 DEP_LIBS=`$PKG_CONFIG --libs $GLIB_PACKAGES gthread-2.0`
@@ -849,6 +855,7 @@
 
 Optional dependencies:
   GTK+:           $have_gtk
+  GIO:            $have_gio
   Ruby:           $have_ruby
   Lua:            $have_lua
   Cairo:          $have_cairo
Index: gegl/gegl-init.c
===================================================================
--- gegl/gegl-init.c	(revision 2307)
+++ gegl/gegl-init.c	(working copy)
@@ -227,7 +227,9 @@
 }
 
 void gegl_tile_backend_ram_stats (void);
+#if HAVE_GIO
 void gegl_tile_backend_tiledir_stats (void);
+#endif
 void gegl_tile_backend_file_stats (void);
 
 void
@@ -256,7 +258,9 @@
       gegl_buffer_stats ();
       gegl_tile_backend_ram_stats ();
       gegl_tile_backend_file_stats ();
+#if HAVE_GIO
       gegl_tile_backend_tiledir_stats ();
+#endif
     }
   global_time = gegl_ticks () - global_time;
   gegl_instrument ("gegl", "gegl", global_time);
Index: gegl/buffer/gegl-buffer-load.c
===================================================================
--- gegl/buffer/gegl-buffer-load.c	(revision 2307)
+++ gegl/buffer/gegl-buffer-load.c	(working copy)
@@ -21,7 +21,14 @@
 #include <string.h>
 #include <errno.h>
 
+#if HAVE_GIO
 #include <gio/gio.h>
+#else
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#endif
 #include <glib-object.h>
 
 #include "gegl-types.h"
@@ -49,8 +56,12 @@
   GeglBufferHeader header;
   GList           *tiles;
   gchar           *path;
+#if HAVE_GIO
   GFile           *file;
   GInputStream    *i;
+#else
+  int              i;
+#endif
   gint             tile_size;
   Babl            *format;
   goffset          offset;
@@ -62,7 +73,11 @@
 {
   info->offset = offset;
   GEGL_NOTE (BUFFER_LOAD, "seek to %i", offset);
+#if HAVE_GIO
   if(!g_seekable_seek (G_SEEKABLE (info->i), info->offset, G_SEEK_SET, NULL, NULL))
+#else
+  if(lseek (info->i, info->offset, SEEK_SET) == -1)
+#endif
     {
       g_warning ("failed seeking");
     }
@@ -75,11 +90,15 @@
     return;
   if (info->path)
     g_free (info->path);
+#if HAVE_GIO
   if (info->i)
     g_object_unref (info->i);
   if (info->file)
     g_object_unref (info->file);
-
+#else
+  if (info->i != -1)
+    close (info->i);
+#endif
   if (info->tiles != NULL)
     {
       GList *iter;
@@ -93,24 +112,42 @@
   g_slice_free (LoadInfo, info);
 }
 
+#if HAVE_GIO
 GeglBufferItem *
 gegl_buffer_read_header (GInputStream *i,
                          goffset      *offset)
+#else
+GeglBufferItem *
+gegl_buffer_read_header (int i,
+                         goffset      *offset)
+#endif
 {
   goffset         placeholder;
   GeglBufferItem *ret;
   if (offset==0)
     offset = &placeholder;
 
+#if HAVE_GIO
   if(!g_seekable_seek (G_SEEKABLE (i), 0, G_SEEK_SET, NULL, NULL))
-      g_warning ("failed seeking to %i", 0);
+#else
+  if(lseek(i, 0, SEEK_SET) == -1)
+#endif
+    g_warning ("failed seeking to %i", 0);
   *offset = 0;
 
   ret = g_malloc (sizeof (GeglBufferHeader));
+#if HAVE_GIO
   *offset += g_input_stream_read (i,
                    ((gchar*)ret),
                    sizeof(GeglBufferHeader),
                    NULL, NULL);
+#else
+  {
+    ssize_t sz_read = read(i, ret, sizeof(GeglBufferHeader));
+    if (sz_read != -1)
+      *offset += sz_read;
+  }
+#endif
 
   GEGL_NOTE (BUFFER_LOAD, "read header: tile-width: %i tile-height: %i next:%i  %ix%i\n",
                    ret->header.tile_width,
@@ -135,22 +172,39 @@
  * is passed in the offset stored at the location is used as the initial seeking
  * point and will be updated with the offset after the read is completed.
  */
+#if HAVE_GIO
 static GeglBufferItem *read_block (GInputStream *i,
                                    goffset      *offset)
+#else
+static GeglBufferItem *read_block (int           i,
+                                   goffset      *offset)
+#endif
 {
   GeglBufferBlock block;
   GeglBufferItem *ret;
-  gsize           read = 0;
+  gsize           byte_read = 0;
   gint            own_size=0;
 
   if (*offset==0)
     return NULL;
 
   if (offset)
+#if HAVE_GIO
     if(!g_seekable_seek (G_SEEKABLE (i), *offset, G_SEEK_SET, NULL, NULL))
+#else
+    if(lseek(i, *offset, SEEK_SET) == -1)
+#endif
       g_warning ("failed seeking to %i", (gint)*offset);
 
-  read += g_input_stream_read (i, &block, sizeof (GeglBufferBlock), NULL, NULL);
+#if HAVE_GIO
+  byte_read += g_input_stream_read (i, &block, sizeof (GeglBufferBlock), NULL, NULL);
+#else 
+  {
+	ssize_t sz_read = read (i, &block,  sizeof (GeglBufferBlock));
+    if(sz_read != -1)
+      byte_read += sz_read;
+  }
+#endif
   GEGL_NOTE (BUFFER_LOAD, "read block: length:%i next:%i",
                           block.length, (guint)block.next);
 
@@ -179,18 +233,36 @@
        */
       ret = g_malloc (own_size);
       memcpy (ret, &block, sizeof (GeglBufferBlock));
-      read += g_input_stream_read (i, ((gchar*)ret) + sizeof(GeglBufferBlock),
+#if HAVE_GIO
+      byte_read += g_input_stream_read (i, ((gchar*)ret) + sizeof(GeglBufferBlock),
                                        own_size - sizeof(GeglBufferBlock),
                                        NULL, NULL);
+#else
+      {
+        ssize_t sz_read = read (i, ((gchar*)ret) + sizeof(GeglBufferBlock),
+                                own_size - sizeof(GeglBufferBlock));
+        if(sz_read != -1)
+          byte_read += sz_read;
+      }
+#endif
       ret->block.length = own_size;
     }
   else if (block.length < own_size)
     {
       ret = g_malloc (own_size);
       memcpy (ret, &block, sizeof (GeglBufferBlock));
-      read += g_input_stream_read (i, ((gchar*)ret) + sizeof(GeglBufferBlock),
+#if HAVE_GIO
+      byte_read += g_input_stream_read (i, ((gchar*)ret) + sizeof(GeglBufferBlock),
                                        block.length - sizeof (GeglBufferBlock),
                                        NULL, NULL);
+#else
+      {
+        ssize_t sz_read = read (i, ret + sizeof(GeglBufferBlock),
+								block.length - sizeof (GeglBufferBlock));
+		if(sz_read != -1)
+		  byte_read += sz_read;
+      }
+#endif
       ret->block.length = own_size;
     }
   else
@@ -199,13 +271,19 @@
       g_warning ("skipping block : of flags:%i\n", block.flags);
     }
 
-  *offset += read;
+  *offset += byte_read;
   return ret;
 }
 
+#if HAVE_GIO
 GList *
 gegl_buffer_read_index (GInputStream *i,
                         goffset      *offset)
+#else
+GList *
+gegl_buffer_read_index (int           i,
+                        goffset      *offset)
+#endif
 /* load the index */
 {
   GList          *ret = NULL;
@@ -247,14 +325,23 @@
   
 
   info->path = g_strdup (path);
+#if HAVE_GIO
   info->file = g_file_new_for_commandline_arg (info->path);
   info->i = G_INPUT_STREAM (g_file_read (info->file, NULL, NULL));
-
+#else
+  info->i = open (info->path, O_RDONLY);
+#endif
   GEGL_NOTE (BUFFER_LOAD, "starting to load buffer %s", path);
+#if HAVE_GIO
   if (!info->i)
+#else
+  if (info->i == -1)
+#endif
     {
       GEGL_NOTE (BUFFER_LOAD, "failed top open %s for reading", path);
+#if HAVE_GIO
       g_object_unref (info->file);
+#endif
       return NULL;
     }
 
@@ -318,9 +405,16 @@
         data = gegl_tile_get_data (tile);
         g_assert (data);
 
+#if HAVE_GIO
         info->offset += g_input_stream_read (info->i, data, info->tile_size,
                                           NULL, NULL);
-
+#else
+        {
+          ssize_t sz_read = read (info->i, data, info->tile_size);
+          if(sz_read != -1)
+            info->offset += sz_read;
+        }
+#endif
         /*g_assert (info->offset == entry->offset + info->tile_size);*/
 
         gegl_tile_unlock (tile);
Index: gegl/buffer/gegl-tile-storage.c
===================================================================
--- gegl/buffer/gegl-tile-storage.c	(revision 2307)
+++ gegl/buffer/gegl-tile-storage.c	(working copy)
@@ -24,7 +24,9 @@
 #include "gegl-tile.h"
 #include "gegl-tile-backend-file.h"
 #include "gegl-tile-backend-ram.h"
+#if HAVE_GIO
 #include "gegl-tile-backend-tiledir.h"
+#endif
 #include "gegl-tile-handler-empty.h"
 #include "gegl-tile-handler-zoom.h"
 #include "gegl-tile-handler-cache.h"
Index: gegl/buffer/gegl-buffer-save.c
===================================================================
--- gegl/buffer/gegl-buffer-save.c	(revision 2307)
+++ gegl/buffer/gegl-buffer-save.c	(working copy)
@@ -20,7 +20,15 @@
 
 #include <string.h>
 
+#if HAVE_GIO
 #include <gio/gio.h>
+#else
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#endif
+
 #include <glib-object.h>
 
 #include "gegl-types.h"
@@ -45,8 +53,12 @@
   GeglBufferHeader header;
   GList           *tiles;
   gchar           *path;
+#if HAVE_GIO
   GFile           *file;
   GOutputStream   *o;
+#else
+  int             o;
+#endif
 
   gint             tile_size;
   gint             offset;
@@ -93,7 +105,13 @@
        if (block == NULL)
          info->in_holding->next = 0;
 
+#if HAVE_GIO
        ret = g_output_stream_write (info->o, info->in_holding, info->in_holding->length, NULL, NULL);
+#else
+       ret = write (info->o, info->in_holding, info->in_holding->length);
+	   if (ret == -1) 
+         ret = 0;
+#endif
        info->offset += ret;
        g_assert (allocated_pos == info->offset);
      }
@@ -111,10 +129,15 @@
     return;
   if (info->path)
     g_free (info->path);
+#if HAVE_GIO
   if (info->o)
     g_object_unref (info->o);
   if (info->file)
     g_object_unref (info->file);
+#else
+  if (info->o != -1)
+    close (info->o);
+#endif
   if (info->tiles != NULL)
     {
       GList *iter;
@@ -209,9 +232,12 @@
    */
 
   info->path = g_strdup (path);
+#if HAVE_GIO
   info->file = g_file_new_for_commandline_arg (info->path);
   info->o    = G_OUTPUT_STREAM (g_file_replace (info->file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL));
-
+#else
+  info->o    = open (info->path, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
+#endif
   g_object_get (buffer, "px-size", &bpp, NULL);
   info->header.x           = buffer->extent.x;
   info->header.y           = buffer->extent.y;
@@ -312,7 +338,15 @@
   }
 
   /* save the header */
+#if HAVE_GIO
   info->offset += g_output_stream_write (info->o, &info->header, sizeof (GeglBufferHeader), NULL, NULL);
+#else
+  {
+    ssize_t ret = write (info->o, &info->header, sizeof (GeglBufferHeader));
+	if (ret != -1)
+      info->offset += ret;
+  }
+#endif
   g_assert (info->offset == info->header.next);
 
   /* save the index */
@@ -351,7 +385,15 @@
         g_assert (data);
 
         g_assert (info->offset == entry->offset);
+#if HAVE_GIO
         info->offset += g_output_stream_write (info->o, data, info->tile_size, NULL, NULL);
+#else
+        { 
+          ssize_t ret = write (info->o, data, info->tile_size);
+	      if (ret != -1)
+            info->offset += ret;
+        }
+#endif
         g_object_unref (G_OBJECT (tile));
         i++;
       }
Index: gegl/buffer/gegl-buffer-access.c
===================================================================
--- gegl/buffer/gegl-buffer-access.c	(revision 2307)
+++ gegl/buffer/gegl-buffer-access.c	(working copy)
@@ -22,7 +22,9 @@
 
 #include <glib-object.h>
 #include <glib/gprintf.h>
+#if HAVE_GIO
 #include <gio/gio.h>
+#endif
 
 #include "gegl-types.h"
 #include "gegl-buffer-types.h"
Index: gegl/buffer/gegl-buffer.c
===================================================================
--- gegl/buffer/gegl-buffer.c	(revision 2307)
+++ gegl/buffer/gegl-buffer.c	(working copy)
@@ -41,7 +41,9 @@
 #include <glib-object.h>
 #include <glib/gstdio.h>
 #include <glib/gprintf.h>
+#if HAVE_GIO
 #include <gio/gio.h>
+#endif
 
 #include "gegl-types.h"
 
Index: gegl/buffer/gegl-buffer-index.h
===================================================================
--- gegl/buffer/gegl-buffer-index.h	(revision 2307)
+++ gegl/buffer/gegl-buffer-index.h	(working copy)
@@ -122,10 +122,17 @@
 
 void gegl_tile_entry_destroy (GeglBufferTile *entry);
 
+#if HAVE_GIO
 GeglBufferItem *gegl_buffer_read_header(GInputStream *i,
                                         goffset      *offset);
 GList          *gegl_buffer_read_index (GInputStream *i,
                                         goffset      *offset);
+#else
+GeglBufferItem *gegl_buffer_read_header(int i,
+                                        goffset      *offset);
+GList          *gegl_buffer_read_index (int i,
+                                        goffset      *offset);
+#endif
 
 #define struct_check_padding(type, size) \
   if (sizeof (type) != size) \
Index: gegl/buffer/gegl-tile-backend-file.c
===================================================================
--- gegl/buffer/gegl-tile-backend-file.c	(revision 2307)
+++ gegl/buffer/gegl-tile-backend-file.c	(working copy)
@@ -18,7 +18,14 @@
 
 #include "config.h"
 
+#if HAVE_GIO
 #include <gio/gio.h>
+#else
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#endif
 #include <string.h>
 #include <errno.h>
 
@@ -36,9 +43,14 @@
   GeglTileBackend  parent_instance;
 
   gchar           *path;    /* the path to our buffer */
+#if HAVE_GIO
   GFile           *file;    /* gfile refering to our buffer */
   GOutputStream   *o;       /* for writing */
   GInputStream    *i;       /* for reading */
+#else
+  int             o;
+  int             i;
+#endif
   gboolean         exist;   /* the file exist (and we've thus been able
                              * to initialize i and o, the utility_call ensure_exist
                              * should be called before any code using i and o)
@@ -78,11 +90,12 @@
   GList *tiles;
 
   /* cooperative sharing of file */
-
+#if HAVE_GIO
   GFileMonitor    *monitor; /* Before using mmap we'll use GIO's infrastructure
                              * for monitoring the file for changes, this should
                              * also be more portable.
                              */
+#endif
   guint32          rev;     /* revision of last index sync */
 };
 
@@ -107,9 +120,13 @@
 
   ensure_exist (self);
 
+#if HAVE_GIO
   success = g_seekable_seek (G_SEEKABLE (self->i),
                              offset, G_SEEK_SET,
                              NULL, NULL);
+#else
+  success = (lseek (self->i, offset, SEEK_SET) >= 0);
+#endif
   if (success == FALSE)
     {
       g_warning ("unable to seek to tile in buffer: %s", g_strerror (errno));
@@ -119,19 +136,23 @@
 
   while (to_be_read > 0)
     {
-      gint read;
+      gint byte_read;
 
-      read = g_input_stream_read (G_INPUT_STREAM (self->i),
+#if HAVE_GIO
+      byte_read = g_input_stream_read (G_INPUT_STREAM (self->i),
                                  dest + tile_size - to_be_read, to_be_read,
                                  NULL, NULL);
-      if (read <= 0)
+#else
+      byte_read = read (self->i, dest + tile_size - to_be_read, to_be_read);
+#endif
+      if (byte_read <= 0)
         {
           g_message ("unable to read tile data from self: "
                      "%s (%d/%d bytes read)",
-                     g_strerror (errno), read, to_be_read);
+                     g_strerror (errno), byte_read, to_be_read);
           return;
         }
-      to_be_read -= read;
+      to_be_read -= byte_read;
     }
 
 
@@ -150,9 +171,13 @@
 
   ensure_exist (self);
 
+#if HAVE_GIO
   success = g_seekable_seek (G_SEEKABLE (self->o),
                              offset, G_SEEK_SET,
                              NULL, NULL);
+#else
+  success = (lseek (self->o, offset, SEEK_SET) >= 0);
+#endif
   if (success == FALSE)
     {
       g_warning ("unable to seek to tile in buffer: %s", g_strerror (errno));
@@ -163,10 +188,14 @@
   while (to_be_written > 0)
     {
       gint wrote;
+#if HAVE_GIO
       wrote = g_output_stream_write (self->o,
                                      source + tile_size - to_be_written,
                                      to_be_written, NULL, NULL);
-
+#else
+	  wrote = write (self->o, source + tile_size - to_be_written,
+					  to_be_written);
+#endif
       if (wrote <= 0)
         {
           g_message ("unable to write tile data to self: "
@@ -211,8 +240,12 @@
 
           GEGL_NOTE (TILE_BACKEND, "growing file to %i bytes", (gint)self->total);
 
+#if HAVE_GIO
           g_assert (g_seekable_truncate (G_SEEKABLE (self->o),
                     self->total, NULL,NULL));
+#else
+		  g_assert (ftruncate (self->o, self->total) == 0);
+#endif
         }
     }
   dbg_alloc (GEGL_TILE_BACKEND (self)->tile_size);
@@ -240,14 +273,22 @@
 
   ensure_exist (self);
 
+#if HAVE_GIO
   success = g_seekable_seek (G_SEEKABLE (self->o), 0, G_SEEK_SET,
                              NULL, NULL);
+#else
+  success = (lseek (self->o, 0, SEEK_SET) != -1);
+#endif
   if (success == FALSE)
     {
       g_warning ("unable to seek in buffer");
       return FALSE;
     }
+#if HAVE_GIO
   g_output_stream_write (self->o, &(self->header), 256, NULL, NULL);
+#else
+  write (self->o, &(self->header), 256);
+#endif
   GEGL_NOTE (TILE_BACKEND, "Wrote header, next=%i", (gint)self->header.next);
   return TRUE;
 }
@@ -269,9 +310,13 @@
            self->in_holding->next = 0;
          }
 
+#if HAVE_GIO
        if(!g_seekable_seek (G_SEEKABLE (self->o),
                             self->offset, G_SEEK_SET,
                             NULL, NULL))
+#else
+       if(lseek (self->o, self->offset, G_SEEK_SET) == -1)
+#endif
          goto fail;
 
        GEGL_NOTE (TILE_BACKEND, "Wrote block: length:%i flags:%i next:%i at offset %i",
@@ -279,9 +324,18 @@
              self->in_holding->flags,
              (gint)self->in_holding->next,
              (gint)self->offset);
+#if HAVE_GIO
        self->offset += g_output_stream_write (self->o, self->in_holding,
                                               self->in_holding->length,
                                               NULL, NULL);
+#else
+       {
+         ssize_t written = write (self->o, self->in_holding,
+                                  self->in_holding->length);
+         if(written != -1)
+           self->offset += written;
+       }
+#endif
 
        g_assert (next_allocation == self->offset); /* true as long as
                                                       the simple allocation
@@ -297,10 +351,13 @@
                                               * of file, worry about writing
                                               * header inside free list later
                                               */
-
+#if HAVE_GIO
         if(!g_seekable_seek (G_SEEKABLE (self->o),
                              (goffset) self->offset, G_SEEK_SET,
                              NULL, NULL))
+#else
+        if(lseek (self->o, self->offset, G_SEEK_SET) == -1)
+#endif
           goto fail;
      }
    self->in_holding = block;
@@ -506,7 +563,11 @@
     }
 
   write_header (self);
+#if HAVE_GIO
   g_output_stream_flush (self->o, NULL, NULL);
+#else
+  fsync (self->o);
+#endif
 
   GEGL_NOTE (TILE_BACKEND, "flushed %s", self->path);
 
@@ -609,6 +670,7 @@
     {
       GEGL_NOTE (TILE_BACKEND, "finalizing buffer %s", self->path);
 
+#if HAVE_GIO
       if (self->i)
         g_object_unref (self->i);
       if (self->o)
@@ -619,13 +681,27 @@
           g_file_delete  (self->file, NULL, NULL);
           g_object_unref (self->file);
         }
+#else
+      if (self->i != -1) 
+	    {
+          close(self->i);
+          self->i = -1;
+        }
+      if (self->o != -1) 
+	    {
+          close(self->o);
+		  self->o = -1;
+        }
+#endif
     }
 
   if (self->path)
     g_free (self->path);
 
+#if HAVE_GIO
   if (self->monitor)
     g_object_unref (self->monitor);
+#endif
 
   (*G_OBJECT_CLASS (parent_class)->finalize)(object);
 }
@@ -760,6 +836,7 @@
   self->tiles          = NULL;
 }
 
+#if HAVE_GIO
 static void
 file_changed (GFileMonitor        *monitor,
               GFile               *file,
@@ -773,6 +850,8 @@
       load_index (self, TRUE);
     }
 }
+#endif
+
 static GObject *
 gegl_tile_backend_file_constructor (GType                  type,
                                     guint                  n_params,
@@ -787,15 +866,23 @@
   backend = GEGL_TILE_BACKEND (object);
 
   GEGL_NOTE (TILE_BACKEND, "constructing file backend: %s", self->path);
+#if HAVE_GIO
   self->file = g_file_new_for_commandline_arg (self->path);
-
+#else
+  self->i = self->o = -1;
+#endif
   self->index = g_hash_table_new (hashfunc, equalfunc);
 
   /* If the file already exists open it, assuming it is a GeglBuffer. */
+#if HAVE_GIO
   if (g_file_query_exists (self->file, NULL))
+#else
+  if (access (self->path, F_OK) != -1)
+#endif
     {
       goffset offset = 0;
 
+#if HAVE_GIO
       /* Install a monitor for changes to the file in case other applications
        * might be writing to the buffer
        */
@@ -818,6 +905,10 @@
                                                    NULL, NULL));
       self->i = g_object_get_data (G_OBJECT (self->o), "istream");
 #endif
+#else
+	  self->o = open (self->path, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
+	  self->i = self->o;
+#endif
       /*self->i = G_INPUT_STREAM (g_file_read (self->file, NULL, NULL));*/
       self->header = gegl_buffer_read_header (self->i, &offset)->header;
       self->header.rev = self->header.rev -1;
@@ -843,7 +934,9 @@
       self->exist = FALSE; /* this is also the default, the file will be created on demand */
     }
 
+#if HAVE_GIO
   g_assert (self->file);
+#endif
 
   backend->header = &self->header;
 
@@ -876,13 +969,19 @@
       g_output_stream_flush (self->o, NULL, NULL);
       self->i = g_object_get_data (G_OBJECT (self->o), "istream");
 #else
+
+#if HAVE_GIO
       self->o = G_OUTPUT_STREAM (g_file_replace (self->file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL));
       g_output_stream_flush (self->o, NULL, NULL);
+#else
+	  self->o = open (self->path, O_RDWR);
+#endif
 
       self->next_pre_alloc = 256;  /* reserved space for header */
       self->total          = 256;  /* reserved space for header */
+#if HAVE_GIO
       g_assert(g_seekable_seek (G_SEEKABLE (self->o), 256, G_SEEK_SET, NULL, NULL));
-
+#endif
       gegl_buffer_header_init (&self->header,
                                backend->tile_width,
                                backend->tile_height,
@@ -890,14 +989,25 @@
                                backend->format
                                );
       write_header (self);
+#if HAVE_GIO
       g_output_stream_flush (self->o, NULL, NULL);
       self->i = G_INPUT_STREAM (g_file_read (self->file, NULL, NULL));
+#else
+      fsync (self->o);
+      self->i = open (self->path, O_RDONLY);  
 #endif
+
+#endif
       /*self->i = G_INPUT_STREAM (g_file_read (self->file, NULL, NULL));*/
       self->next_pre_alloc = 256;  /* reserved space for header */
       self->total          = 256;  /* reserved space for header */
+#if HAVE_GIO
       g_assert (self->i);
       g_assert (self->o);
+#else
+      g_assert (self->i != -1);
+      g_assert (self->o != -1);      
+#endif
     }
 }
 
@@ -931,9 +1041,14 @@
 gegl_tile_backend_file_init (GeglTileBackendFile *self)
 {
   self->path           = NULL;
+#if HAVE_GIO
   self->file           = NULL;
   self->i              = NULL;
   self->o              = NULL;
+#else
+  self->i              = -1;
+  self->o              = -1;
+#endif
   self->index          = NULL;
   self->free_list      = NULL;
   self->next_pre_alloc = 256;  /* reserved space for header */
@@ -951,7 +1066,11 @@
     }
   self->header.flags += GEGL_FLAG_LOCKED;
   write_header (self);
+#if HAVE_GIO
   g_output_stream_flush (self->o, NULL, NULL);
+#else
+  fsync (self->o);
+#endif
   return TRUE;
 }
 
@@ -964,6 +1083,10 @@
     }
   self->header.flags -= GEGL_FLAG_LOCKED;
   write_header (self);
+#if HAVE_GIO
   g_output_stream_flush (self->o, NULL, NULL);
+#else
+  fsync (self->o);
+#endif
   return TRUE;
 }
Index: gegl/buffer/Makefile.am
===================================================================
--- gegl/buffer/Makefile.am	(revision 2307)
+++ gegl/buffer/Makefile.am	(working copy)
@@ -1,6 +1,13 @@
 noinst_LTLIBRARIES = libbuffer.la
 
+if HAVE_GIO
+GIO_SUPPORT_SOURCES=\
+    gegl-tile-backend-tiledir.c	\
+    $(null__)
+endif
+
 BUFFER_sources = \
+    $(GIO_SUPPORT_SOURCES)      \
     gegl-buffer.c		\
     gegl-buffer-access.c	\
     gegl-buffer-share.c		\
@@ -19,7 +26,6 @@
     gegl-tile-storage.c		\
     gegl-tile-backend.c		\
     gegl-tile-backend-file.c	\
-    gegl-tile-backend-tiledir.c	\
     gegl-tile-backend-ram.c	\
     gegl-tile-handler.c		\
     gegl-tile-handler-cache.c	\
_______________________________________________
Gegl-developer mailing list
Gegl-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gegl-developer

Reply via email to