In said:
CBFalconer said:
Chapter and verse please.
I think that C99 7.19.1p2:
The types declared are size_t (described in 7.17);
FILE
which is an object type capable of recording all the information
needed to control a stream, including its file position indicator,
a pointer to its associated buffer (if any), an _error indicator_
that records whether a read/write error has occurred, and an
_end-of-file indicator_ that records whether the end of the file
has been reached;
[...]
can be taken to imply that eof must be sticky. If "the end of the
file has been reached", it doesn't later become the case that the end
of the file has not been reached (though some actions, such as a call
to freopen(), explicitly clear the end-of-file indicator).
There is more precise wording in the description of the fgetc function
(all other input functions work as if they use fgetc):
2 If the end-of-file indicator for the input stream pointed to by
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
stream is not set and a next character is present, the fgetc
^^^^^^^^^^^^^^^^^
function obtains that character as an unsigned char converted
to an int and advances the associated file position indicator
for the stream (if defined).
Returns
3 If the end-of-file indicator for the stream is set, or if the
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
stream is at end-of-file, the end-of-file indicator for the
^^^^^^^^^^^^^^^^^^^^^^^^
stream is set and the fgetc function returns EOF. Otherwise, the
fgetc function returns the next character from the input stream
pointed to by stream. If a read error occurs, the error indicator
for the stream is set and the fgetc function returns EOF.
No mention that fgetc() could reset, under *any* condition, the
end-of-file indicator of the corresponding stream. So, once a fgetc()
call has set the end-of-file indicator by reading from a stream that was
at end-of-file, further fgetc() calls won't even attempt to read from that
stream, because that stream has the end-of-file indicator already set.
The *only* ways of resetting the end-of-file indicator for a stream are
freopen(), ungetc(), fseek(), rewind() and clearerr().
Dan