From c4d5cfc28f476ea9df2529ff9b74a3fd37d279a2 Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Tue, 14 Mar 2006 11:00:05 +0000 Subject: [PATCH] Disable file compression on windows due to missing pipe(2), conditioned on #ifdef _WIN32. Insert code suggestion for windows, but is disabled for now. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13630 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 5 ++ src/backend/file/io-gncxml-v2.c | 97 +++++++++++++++++++++++---------- 2 files changed, 73 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4942e44b98..5007a808f0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2006-03-14 Christian Stimming + * 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 is possible. diff --git a/src/backend/file/io-gncxml-v2.c b/src/backend/file/io-gncxml-v2.c index 36244d6de0..2b72ee004a 100644 --- a/src/backend/file/io-gncxml-v2.c +++ b/src/backend/file/io-gncxml-v2.c @@ -1206,46 +1206,85 @@ gnc_book_write_accounts_to_xml_filehandle_v2(QofBackend *be, QofBook *book, FILE 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); - pid = fork(); - switch (pid) { - case -1: - PWARN("Fork call failed. 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; - case 0: /* child */ - close(filedes[1]); - out = gzopen(filename, perms); - if (out == NULL) { - PWARN("child gzopen failed\n"); - exit(0); + 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); } - while ((bytes = read(filedes[0], buffer, BUFLEN)) > 0) - gzwrite(out, buffer, bytes); - gzclose(out); - _exit(0); + /* FIXME: Now need to set up the child process to write to the + file. */ - default: /* parent */ - sleep(2); - close(filedes[0]); - return fdopen(filedes[1], "w"); + 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; + + if (pipe(filedes) < 0) { + PWARN("Pipe call failed. Opening uncompressed file."); + return fopen(filename, perms); + } + + 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); + } + + default: /* parent */ + sleep(2); + close(filedes[0]); + return fdopen(filedes[1], "w"); + } + } +#endif } gboolean