chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-hackers] [PATCH] read-all/read-string doesn't detect EOF in ter


From: Felix
Subject: [Chicken-hackers] [PATCH] read-all/read-string doesn't detect EOF in terminal
Date: Tue, 25 Sep 2012 21:29:59 +0200 (CEST)

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.


cheers,
felix
>From 5e6ad605422c7e52d0dd309e3eca7dd4c5c75625 Mon Sep 17 00:00:00 2001
From: felix <address@hidden>
Date: Tue, 25 Sep 2012 21:19:35 +0200
Subject: [PATCH] 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.
---
 library.scm |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/library.scm b/library.scm
index bb30f39..b17041f 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)) {
-- 
1.7.0.4


reply via email to

[Prev in Thread] Current Thread [Next in Thread]