From 8fa8f80c1a5db7f21730c3f4bf336de2cd894d22 Mon Sep 17 00:00:00 2001
From: Bruce Momjian <bruce@momjian.us>
Date: Tue, 7 Mar 2000 23:49:31 +0000
Subject: [PATCH] I've recently written to pgsql-ports about a problem with
 PG7.0 on NT (Subj: [PORTS] initdb problem on NT with 7.0).  Since nobody
 helped me, I had to find out the reson.  The difference between NT and Linux
 (for instance) is that "open( path, O_RDWR );" opens a file in text mode.  So
 sometime less block can be read than required.

I suggest a following patch.  BTW the situation appeared before, see
hba.c, pqcomm.c and others.


Alexei Zakharov
---
 src/backend/access/transam/xlog.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 3bf62d7e50a..e8d909f71ef 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.10 2000/02/15 03:00:37 thomas Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.11 2000/03/07 23:49:31 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -726,7 +726,11 @@ XLogFileInit(uint32 log, uint32 seg)
 	unlink(path);
 
 tryAgain:
+#ifndef __CYGWIN__
 	fd = open(path, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR);
+#else
+	fd = open(path, O_RDWR|O_CREAT|O_EXCL|O_BINARY, S_IRUSR|S_IWUSR);
+#endif
 	if (fd < 0 && (errno == EMFILE || errno == ENFILE))
 	{
 		fd = errno;
@@ -767,7 +771,11 @@ XLogFileOpen(uint32 log, uint32 seg, bool econt)
 	XLogFileName(path, log, seg);
 
 tryAgain:
+#ifndef __CYGWIN__
 	fd = open(path, O_RDWR);
+#else
+	fd = open(path, O_RDWR | O_BINARY);
+#endif
 	if (fd < 0 && (errno == EMFILE || errno == ENFILE))
 	{
 		fd = errno;
@@ -1083,7 +1091,11 @@ UpdateControlFile()
 	int		fd;
 
 tryAgain:
+#ifndef __CYGWIN__
 	fd = open(ControlFilePath, O_RDWR);
+#else
+	fd = open(ControlFilePath, O_RDWR | O_BINARY);
+#endif
 	if (fd < 0 && (errno == EMFILE || errno == ENFILE))
 	{
 		fd = errno;
@@ -1145,7 +1157,11 @@ BootStrapXLOG()
 	CheckPoint		checkPoint;
 	XLogRecord	   *record;
 
+#ifndef __CYGWIN__
 	fd = open(ControlFilePath, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR);
+#else
+	fd = open(ControlFilePath, O_RDWR|O_CREAT|O_EXCL|O_BINARY, S_IRUSR|S_IWUSR);
+#endif
 	if (fd < 0)
 		elog(STOP, "BootStrapXLOG failed to create control file (%s): %d", 
 					ControlFilePath, errno);
@@ -1249,7 +1265,11 @@ StartupXLOG()
 	 * Open/read Control file
 	 */
 tryAgain:
+#ifndef __CYGWIN__
 	fd = open(ControlFilePath, O_RDWR);
+#else
+	fd = open(ControlFilePath, O_RDWR | O_BINARY);
+#endif
 	if (fd < 0 && (errno == EMFILE || errno == ENFILE))
 	{
 		fd = errno;
-- 
GitLab