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
This commit is contained in:
Christian Stimming
2006-03-14 11:00:05 +00:00
parent 0744c4e591
commit c4d5cfc28f
2 changed files with 73 additions and 29 deletions

View File

@@ -1,5 +1,10 @@
2006-03-14 Christian Stimming <stimming@tuhh.de> 2006-03-14 Christian Stimming <stimming@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 * src/gnome-utils/gnc-druid-provider-multifile-gnome.h: Improve
include order so that building without <glob.h> is possible. include order so that building without <glob.h> is possible.

View File

@@ -1206,46 +1206,85 @@ gnc_book_write_accounts_to_xml_filehandle_v2(QofBackend *be, QofBook *book, FILE
static FILE * static FILE *
try_gz_open (const char *filename, const char *perms, gboolean use_gzip) 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 */ if (strstr(filename, ".gz.") != NULL) /* its got a temp extension */
use_gzip = TRUE; use_gzip = TRUE;
if (!use_gzip) if (!use_gzip)
return fopen(filename, perms); return fopen(filename, perms);
if (pipe(filedes) < 0) { #ifdef _WIN32
PWARN("Pipe call failed. Opening uncompressed file."); PWARN("Compression not implemented on Windows. Opening uncompressed file.");
return fopen(filename, perms); return fopen(filename, perms);
}
pid = fork(); /* Potential implementation: Windows doesn't have pipe(); use
switch (pid) { the g_spawn glib wrappers. */
case -1: {
PWARN("Fork call failed. Opening uncompressed file."); /* Start gzip from a command line, not by fork(). */
return fopen(filename, perms); gchar *argv[] = {"gzip", NULL};
GPid child_pid;
GError *error;
int child_stdin;
case 0: /* child */ g_assert_not_reached(); /* Not yet correctly implemented. */
close(filedes[1]);
out = gzopen(filename, perms); if ( !g_spawn_async_with_pipes(NULL, argv,
if (out == NULL) { NULL, G_SPAWN_SEARCH_PATH,
PWARN("child gzopen failed\n"); NULL, NULL,
exit(0); &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) /* FIXME: Now need to set up the child process to write to the
gzwrite(out, buffer, bytes); file. */
gzclose(out);
_exit(0);
default: /* parent */ return fdopen(child_stdin, "w");
sleep(2);
close(filedes[0]); /* Eventually the GPid must be cleanup up, but not here? */
return fdopen(filedes[1], "w"); /* 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 gboolean