1515 *
1616 *
1717 * IDENTIFICATION
18- *$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.103 2005/01/25 22 :44:31 tgl Exp $
18+ *$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.104 2005/01/26 19 :44:43 tgl Exp $
1919 *
2020 *-------------------------------------------------------------------------
2121 */
2929#include <ctype.h>
3030#include <unistd.h>
3131
32+ #ifdef WIN32
33+ #include <io.h>
34+ #endif
35+
3236#include "pqexpbuffer.h"
3337#include "libpq/libpq-fs.h"
3438
@@ -1709,6 +1713,21 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
17091713AH -> gzOut = 0 ;
17101714AH -> OF = stdout ;
17111715
1716+ /*
1717+ * On Windows, we need to use binary mode to read/write non-text archive
1718+ * formats. Force stdin/stdout into binary mode in case that is what
1719+ * we are using.
1720+ */
1721+ #ifdef WIN32
1722+ if (fmt != archNull )
1723+ {
1724+ if (mode == archModeWrite )
1725+ setmode (fileno (stdout ),O_BINARY );
1726+ else
1727+ setmode (fileno (stdin ),O_BINARY );
1728+ }
1729+ #endif
1730+
17121731#if 0
17131732write_msg (modulename ,"archive format is %d\n" ,fmt );
17141733#endif
@@ -1720,7 +1739,6 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
17201739
17211740switch (AH -> format )
17221741{
1723-
17241742case archCustom :
17251743InitArchiveFmt_Custom (AH );
17261744break ;