bug-gnulib
[Top][All Lists]
Advanced

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

Re: read-file


From: Simon Josefsson
Subject: Re: read-file
Date: Fri, 16 Jun 2006 21:52:09 +0200
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.50 (gnu/linux)

address@hidden (Larry Jones) writes:

> Simon Josefsson writes:
>> 
>> Looking at the code, it seems it depends on whether feof() return true
>> immediately after fopen on a zero-size file.  Does the standards says
>> anything about this?
>
> Not explicitly, but there's nothing to suggest that fopen() can set the
> end-of-file indicator for the stream.  The intent is certainly that only
> read operations set it.  You could probably finesse the whole issue by
> reverting to the previous code and changing the while loop to a do-while
> loop instead.  That would also have one additional benefit:  Whenever I
> see "while (!feof(...))", it's a red flag that whoever wrote the code
> doesn't understand how EOF works in C and the code should not be
> trusted.  Seeing "do {...} while (!feof(...));" doesn't raise the same
> flag.

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...

/Simon




reply via email to

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