This is the mail archive of the
mailing list for the Cygwin project.
Re: short fread(), but no ferror/feof
Peter Astrand wrote:
Dave Korn wrote:
The fix and the problem Peter is seeing are orthogonal.
The fix referred to above fixes this problem:
"Hence, one can see that fread() in unbuffered mode always returns the
specified count instead of the number of elements actually read."
That is why, as Peter has observed, fread() returns the number of
actually read. Without the patch, it would have been returning the entire
number requested, which would have been even wronger.
Ah, thanks for clarifying this.
However Peter's problem is that when fread() does a partial read, it doesn't
set either the EOF mark or the error indication on the file stream. A strict
reading of the fread() specification suggests that it should have set one of
IMO, there's no room for intepretation in this situation: As I stated
in my original post, IEEE Std 1003.1 is very clear:
"fread() shall return the number of elements successfully read which is
less than nitems only if a read error or end-of-file is encountered."
Where in the POSIX standard did you find that above line? I could not locate it
in mine. The line above is in SUSV3. ANSI and C99 are more relaxed and simply
state that the number of elements returned may be less than asked if EOF or an
error has occurred.
Regardless, the behavior is wrong. The same test on a buffered file yields the EOF.
I have posted a patch.
-- Jeff J.
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html