4.2bsd eof flag in stdio

Ron Natalie ron at BRL-TGR
Wed Nov 21 00:54:55 AEST 1984


Doug:

Looking in your beloved System V manuals you will find under READ(2):

	A value of zero is returned when end-of-file has been reached.
and
	When attempting to read a file associated with a tty that has
	no data currently available ... the read will block until the
	data becomes available.

And then looking at the documentation for the TTY driver, where is it
oh yes, it's called TERMIO and it's in the system administrators manual.
Of course, no ordinary user would ever want to change his terminal modes.

	A line is delimited by a new-line (ASCII LF), an  end-of-file
	(ASCII-EOT), or an end-of-line character.

	EOF - may be used to generate an end-of-file from a terminal.
	Thus if there are no characters waiting, which is to say EOF
	occurred at the beginning of line, zero characters will be
	passed back, which is the standard end-of-file indication.


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.

Fread states
	Fread stops appending bytes if an end-of-file or error
	condition occurs.
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.

It is obvious from this, that no distinction is made of EOT chars meaning
anything but the absolute end-of-file on TTY.  If you were attempting to
write a Stdio using the definitions in the manual, you would have to implement
it this way.

You need to stop defining UNIX by whatever bugs AT&T has and penalize
Berkeley because they have fixed a legitimate bug in the original UNIX
code.

-Ron

Like I'm from the Mystic Valley.



More information about the Comp.unix.wizards mailing list