4.2bsd eof flag in stdio

Doug Gwyn <gwyn> gwyn at brl-tgr.ARPA
Wed Nov 21 04:48:25 AEST 1984


[The actual manual entries were somewhat different and clearer.]

This is not the same as saying that EOT "means" EOF.  Only in certain
contexts does it have that effect, as the TERMIO(7) manual entry says.

> What this implies is the zero return from TTY reads are END-OF-FILE
> and should be treated as such.  It is possible to continue reading
> past end of file on some devices such as TTY and Magtape, but that
> doesn't mean you shouldn't handle EOF properly.

Agreed.

> Fread states
> 	Fread stops appending bytes if an end-of-file or error
> 	condition occurs.

And so it does!  But this is on that call, not necessarily on future
calls.  This feature works as advertised on UNIX System V Release 2.0.

> Ferror states
> 	Feof returns non-zero when EOF has previously been detected
> 	reading the named input stream.
> 	Clearerr resets the error indicator and EOF indicator to zero.

Again, this is the way it does work.  The EOF is "latched" until
cleared, but fread() can read past EOF if there is data there.

I'm all for bugs being fixed, if they are really bugs and not just
different ideas about what should be happening.  Perhaps 4.2BSD and
UNIX System V now agree about EOF behavior; that would be a pleasant
change.



More information about the Comp.unix.wizards mailing list