4.2bsd eof flag in stdio

Bill Shannon shannon at sun.uucp
Sat Nov 24 10:39:07 AEST 1984


> Thanks for the example, Bill.  I guess we disagree about what is
> expected here.  The "EOFish" nature of the input is reflected in
> fread()'s short return count; as expected the 0-length read forces
> fread() to return prematurely.  I see no reason for it to "stick"
> at EOF, though.  The programmer certainly can tell that he is at
> EOF from the short count.  Continuing to read the stream is a
> programming error (that happens to work on "ordinary" files,
> unless they are being dynamically appended to), and more than a bit
> sloppy besides (just like the internals of most UNIX utilities).

If you think of fread as the stdio equivalent of read, and you are
prepared to handle input from a terminal, you will not think of a
short return count as cause for alarm.  Certainly the manual page
gave you no reason to think otherwise.

Also, the manual said fread would return NULL on EOF.  I've clearly
presented an example where it did not return NULL on EOF.  We
considered that a bug, in the manual or in the code, and we chose the
code.  The System V Release 2 manual page for fread has been rewritten
so that it corresponds to what the (non-4.2) code actually does.

This is just another example of the inconsistencies between the UNIX
manuals and the code.  One group chose to fix the code ("people have
been programming according to the manual") while another chose to
fix the manual ("no one reads the manuals anyway, the CODE defines
UNIX").

> I see the argument for the other interpretation; I just don't
> agree with it.

The only good argument against the change was compatibility.  That
may be a strong enough reason to change it back, now that AT&T has
clarified the operation of fread.

					Bill Shannon
					Sun Microsystems



More information about the Comp.unix.wizards mailing list