Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: $Revision: 1.6.2.16 $; site mcvax.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!mcvax!aeb From: aeb@mcvax.UUCP Newsgroups: net.unix-wizards Subject: Re: Orphaned Response Message-ID: <-74400@mcvax.UUCP> Date: Tue, 9-Jul-85 23:56:00 EDT Article-I.D.: mcvax.-74400 Posted: Tue Jul 9 23:56:00 1985 Date-Received: Wed, 31-Jul-85 05:28:50 EDT References: <112@desint.UUCP> Lines: 31 Nf-ID: #R:desint:-11200:mcvax:-74400:177600:1183 Nf-From: mcvax!aeb Jul 9 23:56:00 1985 In article <112@desint.UUCP> geoff@desint.UUCP (Geoff Kuenning) writes: >Um, I think errno is specified to be valid only if putchar returns the >constant EOF. Thus, the code should be: > > if (putchar ('\n') == EOF) > perror ("putchar"); > Unfortunately, this is not true. errno is set by system calls, but not by the stdio library routines. Thus, when a stdio library routine fails it may be that errno contains useful information (in case the failure was due to a system call error return), but it may also be that errno contains garbage (in case the library routine detected the error itself). Thus, fopen can fail when all _iob entries are taken; putc can fail when writing to a stream that has not been opened for writing, etc. This means that you cannot reliably use the stdio routines when you want to do error recovery. Example: #include main(){ putchar('\n'); /* sets errno via isatty() */ fclose(stdout); /* make next putchar fail */ if(putchar('\n') == EOF) perror("putchar"); /* produce garbage */ } Again, the call a.out > /dev/null will produce putchar: no such device, and a.out | ... produces putchar: operation not supported on socket.