4.2bsd eof flag in stdio

bruce at ISM780.UUCP bruce at ISM780.UUCP
Thu Nov 29 15:31:17 AEST 1984


>  Bill Shannon says in part:
>  ... 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");
>  }
>
>  ... Where ^D is your EOT character.  If the program terminates
>  when you type ^D then your stdio works properly. ...
>
>                                         ... 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.

I believe your test program doesn't produce the desired results because
it's buggy, not stdio. Try the following on a system that doesn't have a
buggered fread(), notice the call to feof I've inserted:

#include <stdio.h>
char    buf[256];
main()
{
	register int n;
	while (!feof(stdin) && (n = fread(buf, 1, sizeof buf, stdin)))
		fwrite(buf, 1, n, stdout);
	printf("got EOF\n");
}

I've tested this on our VAX IS/3 system (System III stdio) and with our
vanilla SystemV stdio. Both versions produced the desired (i.e., correct)
behaviour.

Bruce Adler             {sdcrdcf,uscvax,ucla-vax,vortex}!ism780!bruce
Interactive Systems     decvax!yale-co!ima!bruce



More information about the Comp.unix.wizards mailing list