[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Re: fgets() fails to read after fread()
On Tue, 31 Aug 2010 16:19:19 +0200, Jean-Yves Migeon
> On 31 Aug 2010 10:01:45 -0000, "amol pise"
>> $ cat lib/libc/stdio/refill.c
>> 1 /* $NetBSD: refill.c,v 1.13 2003/08/07 16:43:30 agc Exp $ */
>> + #if 0
>> 86 /* SysV does not make this test; take it out for
>> 87 if (fp->_flags & __SEOF)
>> 88 return (EOF);
>> + #endif
>> Doing the above modification is enough to work for SysV system ?
>> Please give me inputs on it.
>> Thank You,
> Oops, I wasn't looking at the correct file...
> Yes, removing the sticky EOF check should be enough.
Actually, according to ANSI C:
184.108.40.206 The fread function
The file position indicator for the stream (if
defined) is advanced by the number of characters successfully read.
If an error occurs, the resulting value of the file position indicator
for the stream is indeterminate.
=> So it seems that, if the initial fread() is incomplete (likely to be
your case for EOF), the position indicator is indeterminate. If you want to
be strictly portable, you would rather have to use clearerr() or fsetpos()
before attempting the fgets(), or check that the value returned by fread()
does match the one you passed to it as parameter (and adapt accordingly if
it is not equal).
Your call I guess :)
Main Index |
Thread Index |