[net.unix] Not a typewriter -- really fwrite

daveb@rtech.UUCP (Dave Brower) (06/18/86)

In article <717@axis.UUCP> philip@axis.UUCP (Philip Peake) writes:
>I agree that this is a disgusting state of affairs, and I have recently
>had problems with a code segment as follows:
>
>	fp = fopen(.....);
>	errno = 0;
>	..
>	loop: fwrite(.....);
>	if (errno != 0) /* a write problem occured */
>	{
>		...
>	}
>	..
>
>This bombed out complaining about "Not a teletype", there was in fact,
>no problem at all. The code came from a BSD4.? system, the machine on
>which the problems occured runs S5.2.

The real problem here is that on BSD4.2, there is no *documented* error
return code for fwrite.  If, however, you look at an SV man page, and 
poke around the BSD code, you will find that fwrite(3) really does
return EOF on an error, and that's what you should check, e.g:

	if( fwrite(.....) == EOF ) /* a write problem occured */
	{
		...
	}

I'm sure there will be flames about the original code because "it
doesn't check the error condition," but heck, if it's not in the
documentation, what's a fellow to do?

-dB
-- 
{amdahl, sun, mtxinu, cbosgd}!rtech!daveb