diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2006-08-30 18:06:27 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2006-08-30 18:06:27 +0000 |
commit | 3a6e2ff08a73e08efe2e1c44a32e56d84ff41dfd (patch) | |
tree | 5ebdad4322a6889c51eb4a3b7efeebf618ca7404 /src/port/open.c | |
parent | f6d7ef08a73e42c41c40e50287233e94539ce6e3 (diff) | |
download | postgresql-3a6e2ff08a73e08efe2e1c44a32e56d84ff41dfd.tar.gz postgresql-3a6e2ff08a73e08efe2e1c44a32e56d84ff41dfd.zip |
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
Diffstat (limited to 'src/port/open.c')
-rw-r--r-- | src/port/open.c | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/port/open.c b/src/port/open.c index 4df74d8b51b..268f2d31a24 100644 --- a/src/port/open.c +++ b/src/port/open.c @@ -6,7 +6,7 @@ * * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/port/open.c,v 1.13 2006/06/25 00:18:24 momjian Exp $ + * $PostgreSQL: pgsql/src/port/open.c,v 1.14 2006/08/30 18:06:27 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -19,7 +19,6 @@ #include <fcntl.h> #include <assert.h> -int pgwin32_open(const char *fileName, int fileFlags,...); static int openFlagsToCreateFileFlags(int openFlags) @@ -112,4 +111,32 @@ pgwin32_open(const char *fileName, int fileFlags,...) return fd; } +FILE * +pgwin32_fopen(const char *fileName, const char *mode) +{ + int openmode = 0; + int fd; + + if (strstr(mode, "r+")) + openmode |= O_RDWR; + else if (strchr(mode, 'r')) + openmode |= O_RDONLY; + if (strstr(mode, "w+")) + openmode |= O_RDWR | O_CREAT | O_TRUNC; + else if (strchr(mode, 'w')) + openmode |= O_WRONLY | O_CREAT | O_TRUNC; + if (strchr(mode, 'a')) + openmode |= O_WRONLY | O_APPEND; + + if (strchr(mode, 'b')) + openmode |= O_BINARY; + if (strchr(mode, 't')) + openmode |= O_TEXT; + + fd = pgwin32_open(fileName, openmode); + if (fd == -1) + return NULL; + return _fdopen(fd, mode); +} + #endif |