Skip to content

Commit e15ce61

Browse files
committed
Cleanup pgwin32_open() 'if' test, and avoid possible error.
1 parent 0184c68 commit e15ce61

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/port/open.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
88
*
9-
* $PostgreSQL: pgsql/src/port/open.c,v 1.15 2006/09/24 17:19:53 tgl Exp $
9+
* $PostgreSQL: pgsql/src/port/open.c,v 1.16 2006/10/03 20:44:18 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -105,9 +105,15 @@ pgwin32_open(const char *fileName, int fileFlags,...)
105105
}
106106

107107
/* _open_osfhandle will, on error, set errno accordingly */
108-
if ((fd = _open_osfhandle((long) h, fileFlags & O_APPEND)) < 0 ||
109-
(fileFlags & (O_TEXT | O_BINARY) && (_setmode(fd, fileFlags & (O_TEXT | O_BINARY)) < 0)))
108+
if ((fd = _open_osfhandle((long) h, fileFlags & O_APPEND)) < 0)
110109
CloseHandle(h); /* will not affect errno */
110+
else if (fileFlags & (O_TEXT | O_BINARY) &&
111+
_setmode(fd, fileFlags & (O_TEXT | O_BINARY)) < 0)
112+
{
113+
_close(fd);
114+
return -1;
115+
}
116+
111117
return fd;
112118
}
113119

0 commit comments

Comments
 (0)