~ chicken-core (chicken-5) 4e5ba39639abe206f2e8cf0e2a7647d00e759562
commit 4e5ba39639abe206f2e8cf0e2a7647d00e759562
Author: felix <felix@call-with-current-continuation.org>
AuthorDate: Tue Sep 25 21:19:35 2012 +0200
Commit: Christian Kellermann <ckeen@pestilenz.org>
CommitDate: Fri Sep 28 12:20:18 2012 +0200
Do not clear eof-status of input port when reading from file-port.
Calling "(read-string #f)" or "(read-all)" from csi in a terminal will
not detect EOF, waiting forever for more input. This is caused by
"C_fast_read_string_from_file", which calls clearerr(3) to clear the
error/eof status on encountering EOF. But when the input port is
connected to a terminal, input may still follow and the EOF status
will be lost. The patch removes the call to clearerr(3) and adds
an additional EOF check at the beginning. I'm not 100% sure about
this fix, but it seems to do the job.
Signed-off-by: Christian Kellermann <ckeen@pestilenz.org>
diff --git a/library.scm b/library.scm
index bb30f392..b17041f9 100644
--- a/library.scm
+++ b/library.scm
@@ -106,6 +106,8 @@ fast_read_string_from_file(C_word dest, C_word port, C_word len, C_word pos)
char * buf = ((char *)C_data_pointer (dest) + C_unfix (pos));
C_FILEPTR fp = C_port_file (port);
+ if(feof(fp)) return C_SCHEME_END_OF_FILE;
+
size_t m = fread (buf, sizeof (char), n, fp);
if(m == EOF && errno == EINTR) {
@@ -114,7 +116,6 @@ fast_read_string_from_file(C_word dest, C_word port, C_word len, C_word pos)
}
else if (m < n) {
if (feof (fp)) {
- clearerr (fp);
if (0 == m)
return C_SCHEME_END_OF_FILE;
} else if (ferror (fp)) {
Trap