Skip to content

Commit 3a6e2ff

Browse files
committed
Fix things so that fopen's, not only open's, pass FILE_SHARE_DELETE
and other special flags on Windows. May fix intermittent 'Permission denied' errors. Magnus Hagander
1 parent f6d7ef0 commit 3a6e2ff

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

src/include/port.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/port.h,v 1.96 2006/08/18 15:47:08 momjian Exp $
9+
* $PostgreSQL: pgsql/src/include/port.h,v 1.97 2006/08/30 18:06:27 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -264,12 +264,15 @@ extern bool rmtree(char *path, bool rmtopdir);
264264

265265
#if defined(WIN32) && !defined(__CYGWIN__)
266266

267-
/* open() replacement to allow delete of held files and passing
268-
* of special options. */
267+
/* open() and fopen() replacements to allow deletion of open files and
268+
* passing of other special options.
269+
*/
269270
extern int pgwin32_open(const char *, int,...);
271+
extern FILE *pgwin32_fopen(const char *, const char *);
270272

271273
#ifndef FRONTEND
272274
#define open(a,b,c) pgwin32_open(a,b,c)
275+
#define fopen(a,b) pgwin32_fopen(a,b)
273276
#endif
274277

275278
#define popen(a,b) _popen(a,b)

src/port/open.c

Lines changed: 29 additions & 2 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.13 2006/06/25 00:18:24 momjian Exp $
9+
* $PostgreSQL: pgsql/src/port/open.c,v 1.14 2006/08/30 18:06:27 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -19,7 +19,6 @@
1919
#include <fcntl.h>
2020
#include <assert.h>
2121

22-
int pgwin32_open(const char *fileName, int fileFlags,...);
2322

2423
static int
2524
openFlagsToCreateFileFlags(int openFlags)
@@ -112,4 +111,32 @@ pgwin32_open(const char *fileName, int fileFlags,...)
112111
return fd;
113112
}
114113

114+
FILE *
115+
pgwin32_fopen(const char *fileName, const char *mode)
116+
{
117+
int openmode = 0;
118+
int fd;
119+
120+
if (strstr(mode, "r+"))
121+
openmode |= O_RDWR;
122+
else if (strchr(mode, 'r'))
123+
openmode |= O_RDONLY;
124+
if (strstr(mode, "w+"))
125+
openmode |= O_RDWR | O_CREAT | O_TRUNC;
126+
else if (strchr(mode, 'w'))
127+
openmode |= O_WRONLY | O_CREAT | O_TRUNC;
128+
if (strchr(mode, 'a'))
129+
openmode |= O_WRONLY | O_APPEND;
130+
131+
if (strchr(mode, 'b'))
132+
openmode |= O_BINARY;
133+
if (strchr(mode, 't'))
134+
openmode |= O_TEXT;
135+
136+
fd = pgwin32_open(fileName, openmode);
137+
if (fd == -1)
138+
return NULL;
139+
return _fdopen(fd, mode);
140+
}
141+
115142
#endif

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy