diff options
author | simonmar <unknown> | 2000-04-12 17:33:17 +0000 |
---|---|---|
committer | simonmar <unknown> | 2000-04-12 17:33:17 +0000 |
commit | 313a61d546f55bb2c098ecd0ebb42e15d943201e (patch) | |
tree | 313c27ee549972fb4d9ef886e27c1708d45af9a0 /ghc/lib/std/cbits/readFile.c | |
parent | f016aea1357b8ce5a4f3cd866b32761cfd25f841 (diff) | |
download | haskell-313a61d546f55bb2c098ecd0ebb42e15d943201e.tar.gz |
[project @ 2000-04-12 17:33:16 by simonmar]
This commit fixes the trace/stderr problem, and also fixes some other
problems with the I/O library.
- handles now contain a list of free buffers, which are
guaranteed to be the same size as the primary handle buffer.
- hPutStr now doesn't evaluate any part of the input string with
the handle locked. Instead, it acquires a buffer from the handle
copies characters into it, then commits the buffer. This is
better for concurrency too, because the handle is only locked
while we're actually reading/writing, not while evaluating.
- there were an even number of off-by-one errors in the I/O system
which compensated for each other. This has been fixed.
- made the I/O subsystem a little more exception-safe. It still
isn't totally exception-safe, but I can't face doing that
without a complete rewrite of this thing in Haskell.
- add hPutBufFull and hGetBufFull. The compiler probably needs to
be updated to use these too.
Diffstat (limited to 'ghc/lib/std/cbits/readFile.c')
-rw-r--r-- | ghc/lib/std/cbits/readFile.c | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/ghc/lib/std/cbits/readFile.c b/ghc/lib/std/cbits/readFile.c index 5c9256cd5a..8393d071c3 100644 --- a/ghc/lib/std/cbits/readFile.c +++ b/ghc/lib/std/cbits/readFile.c @@ -1,7 +1,7 @@ /* * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998 * - * $Id: readFile.c,v 1.14 2000/04/04 11:01:33 simonmar Exp $ + * $Id: readFile.c,v 1.15 2000/04/12 17:33:16 simonmar Exp $ * * hGetContents Runtime Support */ @@ -114,6 +114,7 @@ readBlock(StgForeignPtr ptr) * buffer of connected handle. * FILEOBJ_BLOCKED_READ didn't read anything; would block * n, where n > 0 read n bytes into buffer. + * 0 EOF has been reached */ StgInt @@ -134,9 +135,7 @@ readChunk(StgForeignPtr ptr, StgAddr buf, StgInt off, StgInt len) return -2; if ( FILEOBJ_IS_EOF(fo) ) { - ghc_errtype = ERR_EOF; - ghc_errstr = ""; - return -1; + return 0; } /* if input stream is connect to an output stream, flush it first */ @@ -191,24 +190,20 @@ readChunk(StgForeignPtr ptr, StgAddr buf, StgInt off, StgInt len) /* EOF */ if ( count == 0 ) { FILEOBJ_SET_EOF(fo); - if ( total_count == 0 ) { - ghc_errtype = ERR_EOF; - ghc_errstr = ""; - return -1; - } else { - return total_count; - } + return total_count; + } /* Blocking */ - } else if ( count == -1 && errno == EAGAIN) { + else if ( count == -1 && errno == EAGAIN) { errno = 0; if (total_count > 0) return total_count; /* partial read */ else return FILEOBJ_BLOCKED_READ; + } /* Error */ - } else if ( count == -1 && errno != EINTR) { + else if ( count == -1 && errno != EINTR) { cvtErrno(); stdErrno(); return -1; @@ -268,9 +263,10 @@ readLine(StgForeignPtr ptr) fo->flags = (fo->flags & ~FILEOBJ_RW_WRITE) | FILEOBJ_RW_READ; if ( fo->bufRPtr < 0 || fo->bufRPtr >= fo->bufWPtr ) { /* Buffer is empty */ - fo->bufRPtr=0; fo->bufWPtr=0; - rc = fill_up_line_buffer(fo); - if (rc < 0) return rc; + fo->bufRPtr=0; + fo->bufWPtr=0; + rc = fill_up_line_buffer(fo); + if (rc < 0) return rc; } while (1) { |