From b3820a206f272f89b6bef71572099d279201425f Mon Sep 17 00:00:00 2001 From: sof Date: Wed, 22 Apr 1998 13:03:53 +0000 Subject: [PATCH] [project @ 1998-04-22 13:03:52 by sof] cygwin32 workaround for buggy implementation of file I/O --- ghc/lib/std/cbits/directoryAux.lc | 2 +- ghc/lib/std/cbits/openFile.lc | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ghc/lib/std/cbits/directoryAux.lc b/ghc/lib/std/cbits/directoryAux.lc index 2b352c3..cc67e00 100644 --- a/ghc/lib/std/cbits/directoryAux.lc +++ b/ghc/lib/std/cbits/directoryAux.lc @@ -64,7 +64,7 @@ StgAddr dir; cvtErrno(); stdErrno(); (void) closedir((DIR*)dir); - return 1; + return NULL; } errno = 0; } diff --git a/ghc/lib/std/cbits/openFile.lc b/ghc/lib/std/cbits/openFile.lc index 4b92aca..fb4bdfb 100644 --- a/ghc/lib/std/cbits/openFile.lc +++ b/ghc/lib/std/cbits/openFile.lc @@ -51,7 +51,24 @@ StgByteArray how; exclusive = 1; break; case 'r': +#if defined(cygwin32_TARGET_OS) + /* With cygwin32-b19, fdopen() returns EBADF under some + hard-to-reproduce situations (causing hsc's renamer + to break on some ~10 modules when recompiling it.) + As a temporary workaround, we open files that was requested + opened as read-only instead as read-write, since fdopen() + only appears to fail on RO file descriptors. + + This won't have any impact on the correctness of the Haskell IO + implementation since the Handle in Haskell land will record the + file as being read-only, so illegal writes will be caught. + + ToDo: isolate and report. + */ + oflags = how[1] == '+' ? O_RDWR | O_NOCTTY : O_RDWR | O_NOCTTY; +#else oflags = how[1] == '+' ? O_RDWR | O_NOCTTY : O_RDONLY | O_NOCTTY; +#endif exclusive = 0; break; default: @@ -203,6 +220,9 @@ StgByteArray how; errno = 0; /* Just in case fdopen() is lame */ while ((fp = fdopen(fd, how)) == NULL) { if (errno != EINTR) { +#if defined(cygwin32_TARGET_OS) && defined(DEBUG) + fprintf(stderr, "openFile %s : %s : %d : %d\n", file, how, errno, fd); +#endif cvtErrno(); if (created) (void) unlink(file); -- 1.7.10.4