4.2bsd eof flag in stdio

Bill Shannon shannon at sun.uucp
Tue Nov 20 09:11:06 AEST 1984


> fread() returns 0 if there are 0 characters left in the terminal
> input queue when the ^D is typed.  What would you have it do?

Try this program on your favorite version of stdio:

#include <stdio.h>

char	buf[256];

main()
{
	register int n;

	while (n = fread(buf, 1, sizeof buf, stdin))
		fwrite(buf, 1, n, stdout);
	printf("got EOF\n");
}

Run it and type (e.g.):

testing 1 2 3
^D
another test

Where ^D is your EOT character.  If the program terminates
when you type ^D then your stdio works properly.  The 4.1
version of stdio would "eat" the ^D and echo the first and
third lines.  It would only terminate if you typed ^D twice
in a row.

> If the 4.2BSD fread() was buggy, it should have been fixed rather
> than introducing a significant incompatibility with other STDIOs.

Making EOF sticky was the fix.  It seemed like the right thing to
do; the incompatibility was unfortunate.  If you have a fix to
fread (filbuf, actually) that both fixes this bug and avoids the
incompatibility then please send it to me and/or post it to the
net.  If this works properly in System V I would be interested to
hear that as well.

					Bill Shannon
					Sun Microsystems, Inc.



More information about the Comp.unix.wizards mailing list