From a1c77f6ea0fb4f34849a6a918a8a2ee5e8132018 Mon Sep 17 00:00:00 2001
From: Shenhao Wang <wangsh.fnst@cn.fujitsu.com>
Date: Thu, 7 Jan 2021 19:49:25 +0800
Subject: [PATCH] set text mode when reading backup_label and tablesapce_map

---
 src/backend/access/transam/xlog.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index ede93ad7fd..4c5a45a22d 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -11675,6 +11675,10 @@ read_backup_label(XLogRecPtr *checkPointLoc, bool *backupEndRequired,
 		return false;			/* it's not there, all is fine */
 	}
 
+#ifdef WIN32
+	_setmode(_fileno(lfp), _O_TEXT);
+#endif
+
 	/*
 	 * Read and parse the START WAL LOCATION and CHECKPOINT lines (this code
 	 * is pretty crude, but we are not expecting any variability in the file
@@ -11794,6 +11798,10 @@ read_tablespace_map(List **tablespaces)
 		return false;			/* it's not there, all is fine */
 	}
 
+#ifdef WIN32
+	_setmode(_fileno(lfp), _O_TEXT);
+#endif
+
 	/*
 	 * Read and parse the link name and path lines from tablespace_map file
 	 * (this code is pretty crude, but we are not expecting any variability in
-- 
2.26.2

