4.2bsd eof flag in stdio

Bill Shannon shannon at sun.uucp
Fri Nov 16 19:49:36 AEST 1984


Ben Goldfarb writes,
> Why did Berkeley change stdio such that typing ^D (or whatever EOF character
> one is using) on stdin causes that stream to reflect eof until a clearerr()
> is done?  Has this been discussed here before?  If so, I apologize for 
> further belaboring the issue.
> 
> In any case, what is the correct approach to this problem?  Obviously, we
> can't expect the authors of programs that have been distributed with UNIX
> since V7 to have provided for Berkeley's change; as it stands I've found
> that addbib and learn are both broken because of the continual EOF.  So I
> patched
> 		if (feof(stdin))
> 			clearerr(stdin);
> into both programs.  I'm sure more are affected.  Alternatively, I could have
> "fixed" stdio, but how many Berkeley programs make use of this "feature?"
> I'd appreciate some net wisdom on the subject.  

The change was made by Sun and bought back by Berkeley.  I believe this
has been discussed on the net before.  The change actually fixes another
bug.  The bug was that without this change programs using fread on terminals
would never report an EOF condition to the user because internally fread
would just swallow the EOF and return a short record and the next fread
would go on reading past the EOF.  We actually ran into this bug in some
existing program, I forget which one.  Unfortunately, not all the programs
which depended on the old behaviour were fixed.

					Bill Shannon
					Sun Microsystems, Inc.



More information about the Comp.unix.wizards mailing list