diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index c94ef6305ebdc63afcc664170deb7a50b61258e8..ae22e7d9fb89db67d187aa2e43cfe5db42011d9d 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -490,15 +490,7 @@ readfile(const char *path)
 	char	   *buffer;
 	int			c;
 
-#ifdef WIN32
-	/*
-	 * On Windows, we have to open the file in text mode so that carriage
-	 * returns are stripped.
-	 */
-	if ((infile = fopen(path, "rt")) == NULL)
-#else
 	if ((infile = fopen(path, "r")) == NULL)
-#endif
 	{
 		fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"),
 				progname, path, strerror(errno));
diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c
index 1c9c7408b9776e888ab0600f9d2f2a3421c7f62c..ed9d7f6378a57c963383b0366505d1d0707dc0c1 100644
--- a/src/bin/pg_basebackup/pg_receivewal.c
+++ b/src/bin/pg_basebackup/pg_receivewal.c
@@ -287,7 +287,7 @@ FindStreamingStart(uint32 *tli)
 
 			snprintf(fullpath, sizeof(fullpath), "%s/%s", basedir, dirent->d_name);
 
-			fd = open(fullpath, O_RDONLY | PG_BINARY, 0);
+			fd = open(fullpath, O_RDONLY | PG_BINARY);
 			if (fd < 0)
 			{
 				fprintf(stderr, _("%s: could not open compressed file \"%s\": %s\n"),
diff --git a/src/bin/pg_verify_checksums/pg_verify_checksums.c b/src/bin/pg_verify_checksums/pg_verify_checksums.c
index 1bc020ab6cab1359e78c4f734bc76c240ecadd32..589a3cc58988f2716041efa5519a608196824e4f 100644
--- a/src/bin/pg_verify_checksums/pg_verify_checksums.c
+++ b/src/bin/pg_verify_checksums/pg_verify_checksums.c
@@ -80,7 +80,7 @@ scan_file(const char *fn, BlockNumber segmentno)
 	int			f;
 	BlockNumber blockno;
 
-	f = open(fn, O_RDONLY | PG_BINARY, 0);
+	f = open(fn, O_RDONLY | PG_BINARY);
 	if (f < 0)
 	{
 		fprintf(stderr, _("%s: could not open file \"%s\": %s\n"),
diff --git a/src/common/file_utils.c b/src/common/file_utils.c
index d952bc8c88262ebe9a677db2b4ce455b71528b22..48876061c384d926d76629b04edd3f7ca1f9e755 100644
--- a/src/common/file_utils.c
+++ b/src/common/file_utils.c
@@ -222,7 +222,7 @@ pre_sync_fname(const char *fname, bool isdir, const char *progname)
 {
 	int			fd;
 
-	fd = open(fname, O_RDONLY | PG_BINARY, 0);
+	fd = open(fname, O_RDONLY | PG_BINARY);
 
 	if (fd < 0)
 	{
@@ -283,7 +283,7 @@ fsync_fname(const char *fname, bool isdir, const char *progname)
 	 * unsupported operations, e.g. opening a directory under Windows), and
 	 * logging others.
 	 */
-	fd = open(fname, flags, 0);
+	fd = open(fname, flags);
 	if (fd < 0)
 	{
 		if (errno == EACCES || (isdir && errno == EISDIR))
diff --git a/src/include/port.h b/src/include/port.h
index 9c0848f879a78ce96494374b113147d6ed8b9468..0ce72e50e5e85cdb0956d17252534468fcca067d 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -249,8 +249,11 @@ extern bool rmtree(const char *path, bool rmtopdir);
 #define		O_DIRECT	0x80000000
 extern int	pgwin32_open(const char *, int,...);
 extern FILE *pgwin32_fopen(const char *, const char *);
+
+#ifndef FRONTEND
 #define		open(a,b,c) pgwin32_open(a,b,c)
 #define		fopen(a,b) pgwin32_fopen(a,b)
+#endif
 
 /*
  * Mingw-w64 headers #define popen and pclose to _popen and _pclose.  We want