[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Re: fgets() fails to read after fread()
Thanks for the quick response.
I am using NetBsd-3.1 library on my linux system (SysV). The
lib/libc/stdio/fgets.c code snippet is as below:
$ cat lib/libc/stdio/fgets.c
1 /* $NetBSD: fgets.c,v 1.20 2003/12/14 23:56:28 lukem Exp $ */
If I do the following fix in NetBsd library it works for me.
(i.e. Commenting the sticky EOF check)
$ 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 compatibility */
87 if (fp->_flags & __SEOF)
88 return (EOF);
Doing the above modification is enough to work for SysV system ?
Please give me inputs on it.
On Tue, 31 Aug 2010 14:07:05 +0530 wrote
On 30 Aug 2010 15:50:44 -0000, "amol pise"
> Here, at line 89, it checks for __SEOF (i.e. sticky EOF) flag, and if it
> set then it returns EOF at line 90. (In my scenario this flag was set by
> fread() at (A)). Hence it returns EOF.
> Then I decided to comment out this EOF check in refill.c (line:89) and
> observed fgets() is able to read "Hello" without any issue.
> Can you give me some more inputs why this EOF sticky bit check present
> NetBsd ? Is it required ?
> I really appreciate the inputs on it.
I suppose it is some kind of divergence between SysV and BSD paradigms.
Normally, you are not supposed to read data after an EOF, though you can
have situations were it may be possible (like terminals, when you exit a
shell with ^D, and your pipe, when trying to get data through fgets after
One possible fix would be to use another library, or use clearerr() before
Anyway, I can't find the code you are mentioning in my current
lib/libc/stdio/fgets.c -- are you sure this one comes from NetBSD?
Main Index |
Thread Index |