Not a typewriter -- really fwrite
Dave Brower
daveb at rtech.UUCP
Thu Jun 19 03:27:00 AEST 1986
In article <717 at axis.UUCP> philip at 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
More information about the Comp.unix
mailing list