From 8f201640af74c47918f5e9aee3a3e8ceeabe8eff Mon Sep 17 00:00:00 2001
From: Hari <haribabuk@fast.au.fujitsu.com>
Date: Fri, 14 Jul 2017 11:26:30 +1000
Subject: [PATCH 1/2] pg_basebackup windows tar mode to stdout fix

pg_basebackup with tar mode to stdout writes the
data to stdout in open text mode, that introduces the
CR LF characters that gets generated. Because of these
CR LF characters, the generated tar format cannot be
extracted.

To Fix this problem, change the stdout file into a
binary mode instead of text mode, that solves the problem
of geneating CR LF characters.
---
 src/bin/pg_basebackup/pg_basebackup.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 3ad0699..dfb9b5d 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -954,6 +954,10 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
 		 */
 		if (strcmp(basedir, "-") == 0)
 		{
+#ifdef WIN32
+			_setmode(fileno(stdout), _O_BINARY);
+#endif
+
 #ifdef HAVE_LIBZ
 			if (compresslevel != 0)
 			{
-- 
2.7.4.windows.1

