Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site eagle.UUCP Path: utzoo!watmath!clyde!burl!ulysses!eagle!mjs From: mjs@eagle.UUCP (M.J.Shannon) Newsgroups: net.bugs.4bsd,net.unix-wizards Subject: Re: Bug in isatty (BSD4.2) Message-ID: <1277@eagle.UUCP> Date: Wed, 10-Jul-85 12:32:24 EDT Article-I.D.: eagle.1277 Posted: Wed Jul 10 12:32:24 1985 Date-Received: Fri, 12-Jul-85 00:37:37 EDT References: <726@mcvax.UUCP> <112@desint.UUCP> <744@mcvax.UUCP> Organization: AT&T Bell Laboratories, Summit, NJ Lines: 38 Xref: watmath net.bugs.4bsd:1598 net.unix-wizards:13775 > 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. How about using the routine which is part of stdio to determine the presence of errors? I beileve it's called ferror(iop). The only problem is that the programmer must determine what the error was by context..... -- Marty Shannon UUCP: ihnp4!eagle!mjs Phone: +1 201 522 6063