[Top][All Lists]

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

Re: read-file

From: Simon Josefsson
Subject: Re: read-file
Date: Sat, 17 Jun 2006 18:23:50 +0200
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.50 (gnu/linux)

address@hidden (Larry Jones) writes:

> Simon Josefsson writes:
>> OTOH, if the EOF marker is already set, should we really continue to
>> read from the stream?  The function may take an already open stream,
>> that have been read from before.
>> Perhaps the function should also test ferror outside of the loop...
> If either the end-of-file or error indicators are set for the stream,
> the C Standard requires fread to immediately return 0 (aka "sticky"
> EOF).  Most traditional implementations, however, do not do that.  That
> said, I really don't care one way or the other what you do about it.  :-)

But currently read_file will return strdup("") if feof is true,
without checking ferror on the stream.  That seems wrong?  I'm
thinking of this patch.  Unless someone objects, I'll install it.

--- read-file.c 16 Jun 2006 21:26:36 +0200      1.1
+++ read-file.c 17 Jun 2006 18:22:29 +0200      
@@ -43,6 +43,9 @@
   if (!buf)
     return NULL;
+  if (ferror (stream))
+    return NULL;
   while (!feof (stream))
       size_t count;

reply via email to

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