Skip to content

Commit 2402998

Browse files
committed
Fix pg_basebackup output to stdout on Windows.
When writing a backup to stdout with pg_basebackup on Windows, put stdout to binary mode. Any CR bytes in the output will otherwise be output incorrectly as CR+LF. In the passing, standardize on using "_setmode" instead of "setmode", for the sake of consistency. They both do the same thing, but according to MSDN documentation, setmode is deprecated. Fixes bug #14634, reported by Henry Boehlert. Patch by Haribabu Kommi. Backpatch to all supported versions. Discussion: https://www.postgresql.org/message-id/20170428082818.24366.13134@wrigleys.postgresql.org
1 parent 26d8678 commit 2402998

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,10 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
792792
*/
793793
if (strcmp(basedir, "-") == 0)
794794
{
795+
#ifdef WIN32
796+
_setmode(fileno(stdout), _O_BINARY);
797+
#endif
798+
795799
#ifdef HAVE_LIBZ
796800
if (compresslevel != 0)
797801
{

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,9 +2224,9 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
22242224
(AH->fSpec == NULL || strcmp(AH->fSpec, "") == 0))
22252225
{
22262226
if (mode == archModeWrite)
2227-
setmode(fileno(stdout), O_BINARY);
2227+
_setmode(fileno(stdout), O_BINARY);
22282228
else
2229-
setmode(fileno(stdin), O_BINARY);
2229+
_setmode(fileno(stdin), O_BINARY);
22302230
}
22312231
#endif
22322232

0 commit comments

Comments
 (0)