X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=ghc%2Flib%2Fstd%2Fcbits%2FopenFile.c;h=66f7eab6863e083935180acddfd464f6e948d4d7;hb=37782afc3867ca4f4296763b0c81e0a9b6c5e1ca;hp=5be41540e07d64dfbd191c1f5447e2d37e79dd92;hpb=14a15152e2ae117777a8303e5589fc03bdb2e682;p=ghc-hetmet.git diff --git a/ghc/lib/std/cbits/openFile.c b/ghc/lib/std/cbits/openFile.c index 5be4154..66f7eab 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.13 1999/12/08 14:04:32 simonmar Exp $ + * $Id: openFile.c,v 1.18 2000/05/15 09:20:11 simonmar Exp $ * * openFile Runtime Support */ @@ -33,9 +33,7 @@ #endif IOFileObject* -openStdFile(fd,rd) -StgInt fd; -StgInt rd; +openStdFile(StgInt fd, StgInt rd) { IOFileObject* fo; long fd_flags; @@ -46,18 +44,24 @@ StgInt rd; fo->buf = NULL; fo->bufWPtr = 0; fo->bufRPtr = 0; - fo->bufStart = 0; fo->flags = FILEOBJ_STD | ( rd ? FILEOBJ_READ : FILEOBJ_WRITE); fo->connectedTo = NULL; - /* MS Win32 CRT doesn't support fcntl() -- the workaround is to - start using 'completion ports', but I'm punting on implementing - support for using those. - */ #if !defined(_WIN32) || defined(__CYGWIN__) || defined(__CYGWIN32__) - /* set the non-blocking flag on this file descriptor */ - fd_flags = fcntl(fd, F_GETFL); - fcntl(fd, F_SETFL, fd_flags | O_NONBLOCK); + /* Set the non-blocking flag on this file descriptor. + * + * Don't do it for stdout and stderr: some shells (actually most) + * don't reset the nonblocking flag after running a program, and + * this causes all sorts of problems. --SDM (12/99) + * + * MS Win32 CRT doesn't support fcntl() -- the workaround is to + * start using 'completion ports', but I'm punting on implementing + * support for using those. + */ + if (fd != 1 && fd != 2) { + fd_flags = fcntl(fd, F_GETFL); + fcntl(fd, F_SETFL, fd_flags | O_NONBLOCK); + } #endif return fo; @@ -69,12 +73,8 @@ StgInt rd; #define OPENFILE_READ_WRITE 3 IOFileObject* -openFile(file, how, binary) -StgByteArray file; -StgInt how; -StgInt binary; +openFile(StgByteArray file, StgInt how, StgInt binary) { - FILE *fp; int fd; int oflags; int for_writing; @@ -280,7 +280,6 @@ StgInt binary; fo->fd = fd; fo->buf = NULL; - fo->bufStart = 0; fo->bufWPtr = 0; fo->bufRPtr = 0; fo->flags = flags; @@ -290,10 +289,9 @@ StgInt binary; /* `Lock' file descriptor and return file object. */ IOFileObject* -openFd(StgInt fd,StgInt oflags,StgInt flags) +openFd(StgInt fd, StgInt oflags, StgInt flags) { int for_writing; - FILE* fp; IOFileObject* fo; for_writing = ( ((oflags & O_WRONLY) || (oflags & O_RDWR)) ? 1 : 0); @@ -318,7 +316,6 @@ openFd(StgInt fd,StgInt oflags,StgInt flags) return NULL; fo->fd = fd; fo->buf = NULL; - fo->bufStart = 0; fo->bufWPtr = 0; fo->bufRPtr = 0; fo->flags = flags | ( oflags & O_RDONLY ? FILEOBJ_READ