diff options
author | sof <unknown> | 1999-02-04 12:13:16 +0000 |
---|---|---|
committer | sof <unknown> | 1999-02-04 12:13:16 +0000 |
commit | c8f077d42bbd594ec1e2f19f09b6e24364d4e8b4 (patch) | |
tree | 145df967809b81ff4a6d886a54ded9beebb8f305 /ghc/lib/std/cbits/openFile.c | |
parent | 6037e956e9b37b1ef2221de04f2dfb72074d1729 (diff) | |
download | haskell-c8f077d42bbd594ec1e2f19f09b6e24364d4e8b4.tar.gz |
[project @ 1999-02-04 12:13:15 by sof]
- relax the restriction that just the one open writeable handle on
*the same file* may exist when dealing with the standard handles,
stdout and stderr.
Reason: the following invocation of a Haskell program,
foo >log 2>&1
should be acceptable.
Diffstat (limited to 'ghc/lib/std/cbits/openFile.c')
-rw-r--r-- | ghc/lib/std/cbits/openFile.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/ghc/lib/std/cbits/openFile.c b/ghc/lib/std/cbits/openFile.c index 2d5afe516b..7d3b217ad2 100644 --- a/ghc/lib/std/cbits/openFile.c +++ b/ghc/lib/std/cbits/openFile.c @@ -1,7 +1,7 @@ /* * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998 * - * $Id: openFile.c,v 1.5 1999/01/23 17:44:40 sof Exp $ + * $Id: openFile.c,v 1.6 1999/02/04 12:13:15 sof Exp $ * * openFile Runtime Support */ @@ -29,6 +29,10 @@ #include <fcntl.h> #endif +#ifdef mingw32_TARGET_OS +#define O_NOCTTY 0 +#endif + IOFileObject* openStdFile(fd,flags,rd) StgInt fd; @@ -63,7 +67,7 @@ StgInt flags; FILE *fp; int fd; int oflags; - int exclusive; + int for_writing; int created = 0; struct stat sb; IOFileObject* fo; @@ -76,19 +80,19 @@ StgInt flags; switch (how) { case OPENFILE_APPEND: oflags = O_WRONLY | O_NOCTTY | O_APPEND; - exclusive = 1; + for_writing = 1; break; case OPENFILE_WRITE: oflags = O_WRONLY | O_NOCTTY; - exclusive = 1; + for_writing = 1; break; case OPENFILE_READ_ONLY: oflags = O_RDONLY | O_NOCTTY; - exclusive = 0; + for_writing = 0; break; case OPENFILE_READ_WRITE: oflags = O_RDWR | O_NOCTTY; - exclusive = 0; + for_writing = 1; break; default: fprintf(stderr, "openFile: unknown mode `%d'\n", how); @@ -110,12 +114,14 @@ StgInt flags; return NULL; } else { /* If it is a dangling symlink, break off now, too. */ +#ifndef mingw32_TARGET_OS struct stat st; if ( lstat(file,&st) == 0) { ghc_errtype = ERR_NOSUCHTHING; ghc_errstr = "dangling symlink"; return NULL; } +#endif } /* Now try to create it */ while ((fd = open(file, oflags | O_CREAT | O_EXCL, 0666)) < 0) { @@ -186,7 +192,7 @@ StgInt flags; } /* Use our own personal locking */ - if (lockFile(fd, exclusive) < 0) { + if (lockFile(fd, for_writing, 1/*enforce single-writer, if needs be.*/) < 0) { cvtErrno(); switch (ghc_errno) { default: @@ -268,11 +274,13 @@ StgInt fd; StgInt oflags; StgInt flags; { - int exclusive; + int for_writing; FILE* fp; IOFileObject* fo; - if (lockFile(fd, exclusive) < 0) { + for_writing = ( ((oflags & O_WRONLY) || (oflags & O_RDWR)) ? 1 : 0); + + if (lockFile(fd, for_writing, 1/* enforce single-writer */ ) < 0) { cvtErrno(); switch (ghc_errno) { default: |