[Gnucash-changes] r13630 - gnucash/trunk - Disable file compression on windows due to missing pipe(2),

Christian Stimming cstim at cvs.gnucash.org
Tue Mar 14 06:00:06 EST 2006


Author: cstim
Date: 2006-03-14 06:00:05 -0500 (Tue, 14 Mar 2006)
New Revision: 13630
Trac: http://svn.gnucash.org/trac/changeset/13630

Modified:
   gnucash/trunk/ChangeLog
   gnucash/trunk/src/backend/file/io-gncxml-v2.c
Log:
Disable file compression on windows due to missing pipe(2), 
conditioned on #ifdef _WIN32. Insert code suggestion for windows, 
but is disabled for now.



Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog	2006-03-14 10:23:44 UTC (rev 13629)
+++ gnucash/trunk/ChangeLog	2006-03-14 11:00:05 UTC (rev 13630)
@@ -1,5 +1,10 @@
 2006-03-14  Christian Stimming <stimming at tuhh.de>
 
+	* src/backend/file/io-gncxml-v2.c: Disable file compression on
+	windows due to missing pipe(2), conditioned on #ifdef
+	_WIN32. Insert code suggestion for windows, but is disabled for
+	now.
+
 	* src/gnome-utils/gnc-druid-provider-multifile-gnome.h: Improve
 	include order so that building without <glob.h> is possible.
 

Modified: gnucash/trunk/src/backend/file/io-gncxml-v2.c
===================================================================
--- gnucash/trunk/src/backend/file/io-gncxml-v2.c	2006-03-14 10:23:44 UTC (rev 13629)
+++ gnucash/trunk/src/backend/file/io-gncxml-v2.c	2006-03-14 11:00:05 UTC (rev 13630)
@@ -1206,46 +1206,85 @@
 static FILE *
 try_gz_open (const char *filename, const char *perms, gboolean use_gzip)
 {
-  char buffer[BUFLEN];
-  unsigned bytes;
-  int filedes[2];
-  gzFile *out;
-  pid_t pid;
-
   if (strstr(filename, ".gz.") != NULL) /* its got a temp extension */
       use_gzip = TRUE;
 
   if (!use_gzip)
     return fopen(filename, perms);
 
-  if (pipe(filedes) < 0) {
-    PWARN("Pipe call failed. Opening uncompressed file.");
-    return fopen(filename, perms);
+#ifdef _WIN32
+  PWARN("Compression not implemented on Windows. Opening uncompressed file.");
+  return fopen(filename, perms);
+
+  /* Potential implementation: Windows doesn't have pipe(); use
+     the g_spawn glib wrappers. */
+  {
+    /* Start gzip from a command line, not by fork(). */
+    gchar *argv[] = {"gzip", NULL};
+    GPid child_pid;
+    GError *error;
+    int child_stdin;
+
+    g_assert_not_reached(); /* Not yet correctly implemented. */
+
+    if ( !g_spawn_async_with_pipes(NULL, argv,
+				   NULL, G_SPAWN_SEARCH_PATH,
+				   NULL, NULL, 
+				   &child_pid,
+				   &child_stdin, NULL, NULL,
+				   &error) ) {
+      PWARN("G_spawn call failed. Opening uncompressed file.");
+      return fopen(filename, perms);
+    }
+    /* FIXME: Now need to set up the child process to write to the
+       file. */
+
+    return fdopen(child_stdin, "w");
+
+    /* Eventually the GPid must be cleanup up, but not here? */
+    /* g_spawn_close_pid(child_pid); */
   }
+#else
+  {
+    /* Normal Posix platform (non-windows) */
+    int filedes[2];
+    pid_t pid;
 
-  pid = fork();
-  switch (pid) {
-   case -1:
-    PWARN("Fork call failed. Opening uncompressed file.");
-    return fopen(filename, perms);
+    if (pipe(filedes) < 0) {
+      PWARN("Pipe call failed. Opening uncompressed file.");
+      return fopen(filename, perms);
+    }
 
-   case 0: /* child */
-    close(filedes[1]);
-    out = gzopen(filename, perms);
-    if (out == NULL) {
-      PWARN("child gzopen failed\n");
-      exit(0);
+    pid = fork();
+    switch (pid) {
+    case -1:
+      PWARN("Fork call failed. Opening uncompressed file.");
+      return fopen(filename, perms);
+
+    case 0: /* child */ {
+      char buffer[BUFLEN];
+      unsigned bytes;
+      gzFile *out;
+
+      close(filedes[1]);
+      out = gzopen(filename, perms);
+      if (out == NULL) {
+	PWARN("child gzopen failed\n");
+	exit(0);
+      }
+      while ((bytes = read(filedes[0], buffer, BUFLEN)) > 0)
+	gzwrite(out, buffer, bytes);
+      gzclose(out);
+      _exit(0);
     }
-    while ((bytes = read(filedes[0], buffer, BUFLEN)) > 0)
-      gzwrite(out, buffer, bytes);
-    gzclose(out);
-    _exit(0);
 
-   default: /* parent */
-    sleep(2);
-    close(filedes[0]);
-    return fdopen(filedes[1], "w");
+    default: /* parent */
+      sleep(2);
+      close(filedes[0]);
+      return fdopen(filedes[1], "w");
+    }
   }
+#endif
 }
 
 gboolean



More information about the gnucash-changes mailing list