NetBSD-Users archive

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

Re: fgets() fails to read after fread()



On 30 Aug 2010 15:50:44 -0000, "amol pise" <amol_pise%rediffmail.com@localhost>
wrote:
> 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
in
> 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
fread).

One possible fix would be to use another library, or use clearerr() before
fgets.

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?

-- 
Jean-Yves Migeon
jean-yves.migeon%free.fr@localhost




Home | Main Index | Thread Index | Old Index