bug-gnulib
[Top][All Lists]
Advanced

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

Re: read-file


From: Larry Jones
Subject: Re: read-file
Date: Fri, 16 Jun 2006 15:49:06 -0400 (EDT)

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.

-Larry Jones

See if we can sell Mom and Dad into slavery for a star cruiser. -- Calvin




reply via email to

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