Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site cbosgd.UUCP
Path: utzoo!watmath!clyde!cbosgd!ka
From: ka@cbosgd.UUCP (Kenneth Almquist)
Newsgroups: net.unix-wizards
Subject: Re: 4.2bsd eof flag in stdio
Message-ID: <528@cbosgd.UUCP>
Date: Fri, 30-Nov-84 02:23:41 EST
Article-I.D.: cbosgd.528
Posted: Fri Nov 30 02:23:41 1984
Date-Received: Fri, 30-Nov-84 08:22:18 EST
References: <1697@ucf-cs.UUCP> <1796@sun.uucp> <5867@brl-tgr.ARPA> <1246@utah-gr.UUCP> <239@desint.UUCP>
Organization: Bell Labs, Columbus
Lines: 31

> The fact that some programs have in the past misinterpreted this bug as a
> feature and made use of it is unfortunate, but something we will have to
> live with.

Arggh!

The 4.2 BSD manual page for getchar states that, "These functions return
the integer constant EOF at end of file...."  Now for a standard UNIX
file, the end of file is the location immediately above the last byte
written.  Thus if getchar returns EOF, something is appended to the
input file, and getchar is called again, getchar should not return EOF
because the file pointer is no longer at end of file.

The fact that the 4.2 BSD implementation of getchar handles EOF differ-
ently not only from all other variants of UNIX, but also from the way
its own documentation says it should handle EOF, is indeed "unfortunate,
but something we will have to live with."

If we may believe Bill Shannon, the whole issue arose because nobody
could figure out how to make a straightforward change to fread.  The
change could have been implemented as follows:

1)  Add a new flag named _EOF_PUSHED_BACK to stdio.h.
2)  When _filbuf is called with this flag set, have it clear the flag
    and return EOF.
3)  While a new routine called pushback which is just like ungetc except
    that pushback(EOF, fp) should set _EOF_PUSHED_BACK and return.
4)  When fread encounter EOF and it has read at least one item, have it
    call pushback(EOF, fp) before returning.

				Kenneth Almquist