From b5351cb22536c502ac2cae32c384fc60b996777b Mon Sep 17 00:00:00 2001
From: sof <unknown>
Date: Tue, 18 Aug 1998 12:17:10 +0000
Subject: [PATCH] [project @ 1998-08-18 12:17:10 by sof] readChunk: fixed to
 cope with incomplete reads.

---
 ghc/lib/std/cbits/readFile.lc | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/ghc/lib/std/cbits/readFile.lc b/ghc/lib/std/cbits/readFile.lc
index 9276e0657501..457db8f2665c 100644
--- a/ghc/lib/std/cbits/readFile.lc
+++ b/ghc/lib/std/cbits/readFile.lc
@@ -99,7 +99,7 @@ StgAddr buf;
 StgInt len;
 {
     IOFileObject* fo = (IOFileObject*)ptr;
-    int count=0,rc=0,orig_len;
+    int count=0,rc=0, total_count;
     int fd;
     char* p;
 
@@ -148,20 +148,17 @@ StgInt len;
     if (len - count <= 0)
        return count;
 
-    orig_len = len;
     len -= count;
     p = buf;
     p += count;
+    total_count = count;
 
     if ( fo->flags & FILEOBJ_NONBLOCKING_IO && inputReady (ptr,0) != 1 )
       return FILEOBJ_BLOCKED_READ;
 
     while ((count = read(fd, p, len)) < len) {
-	if ( count == 0 ) {
-            FILEOBJ_SET_EOF(fo);
-	    ghc_errtype = ERR_EOF;
-	    ghc_errstr = "";
-	    return -1;
+	if ( count == 0 ) { /* EOF */
+	    return total_count;
 	} else if ( count == -1 && errno == EAGAIN) {
 	    errno = 0;
 	    return FILEOBJ_BLOCKED_READ;
@@ -170,13 +167,14 @@ StgInt len;
 	    stdErrno();
 	    return -1;
 	}
+        total_count += count;
 	len -= count;
 	p += count;
     }
 
-    fo->bufWPtr = orig_len;
+    fo->bufWPtr = total_count;
     fo->bufRPtr = 0;
-    return count;
+    return total_count;
 }
 
 /*
-- 
GitLab