From b5aef556941daf9d68708e02b94f4b0e672d66e0 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 26 Jan 2005 19:44:53 +0000 Subject: Make pg_dump and pg_restore handle binary archive formats correctly when using stdout/stdin on Windows. --- src/bin/pg_dump/pg_backup_archiver.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index 535c13b317..b424b62621 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -15,7 +15,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.101.4.2 2005/01/25 22:44:46 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.101.4.3 2005/01/26 19:44:53 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -29,6 +29,10 @@ #include #include +#ifdef WIN32 +#include +#endif + #include "pqexpbuffer.h" #include "libpq/libpq-fs.h" @@ -1709,6 +1713,21 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt, AH->gzOut = 0; AH->OF = stdout; + /* + * On Windows, we need to use binary mode to read/write non-text archive + * formats. Force stdin/stdout into binary mode in case that is what + * we are using. + */ +#ifdef WIN32 + if (fmt != archNull) + { + if (mode == archModeWrite) + setmode(fileno(stdout), O_BINARY); + else + setmode(fileno(stdin), O_BINARY); + } +#endif + #if 0 write_msg(modulename, "archive format is %d\n", fmt); #endif @@ -1720,7 +1739,6 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt, switch (AH->format) { - case archCustom: InitArchiveFmt_Custom(AH); break; -- cgit v1.2.1