Skip to content

Commit 9d58b96

Browse files
committed
Make pg_dump and pg_restore handle binary archive formats correctly
when using stdout/stdin on Windows.
1 parent 889f038 commit 9d58b96

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
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
*/
@@ -29,6 +29,10 @@
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,
17091713
AH->gzOut = 0;
17101714
AH->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
17131732
write_msg(modulename, "archive format is %d\n", fmt);
17141733
#endif
@@ -1720,7 +1739,6 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
17201739

17211740
switch (AH->format)
17221741
{
1723-
17241742
case archCustom:
17251743
InitArchiveFmt_Custom(AH);
17261744
break;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy