Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/5/84; site reed.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!harvard!talcott!panda!genrad!decvax!tektronix!reed!alexis From: alexis@reed.UUCP (Alexis Dimitriadis) Newsgroups: net.bugs.4bsd,net.unix-wizards,net.bugs.usg Subject: Re: Bug in isatty (all systems!) Message-ID: <1730@reed.UUCP> Date: Thu, 25-Jul-85 22:18:13 EDT Article-I.D.: reed.1730 Posted: Thu Jul 25 22:18:13 1985 Date-Received: Sun, 28-Jul-85 05:00:54 EDT References: <6367@ucla-cs.ARPA> <997@sdcsvax.UUCP> <1017@ulysses.UUCP> Reply-To: alexis@reed.UUCP (Alexis Dimitriadis) Followup-To: net.unix-wizards Organization: Reed College, Portland, Oregon Lines: 47 Xref: linus net.bugs.4bsd:1324 net.unix-wizards:11225 net.bugs.usg:248 > > ... I designed a large software system around > > the assumption that errno was always valid and not set as a side-effect. > > It took me 6 months (admittedly, I wasn't looking hard) to figure out > > why I was always getting "not a typewriter" (because my open routine > > was setting a struct bit to indicate tty/non-tty for every file). > > My 4.2bsd manual describes this in the INTRO(2) section, right before the > list of errno values. Just where would you prefer that it be mentioned? > RTFM! MY 4.2bsd manual says: ... An error number is also made available in the external variable _errno_, which is not cleared on successful calls. Thus _errno_ should be tested only after an error has occurred. What does "not cleared on successful calls" mean to you? To me, it means that if I set errno = 0 in the beginning of my program, it will stay zero until a system call _fails_, then it will stay non-zero long enough for me to do something about it. Now if a perfectly successful operation sets errno and does not bother to clear it, how can I depend on errno as an indication that something went _wrong_? Remember, TFM does not say anywhere that _successful_ operations set errno, which is what, in effect, happens here. Or should the whole world know how fopen() is implemented, in order to decipher errno in context? If I did not dream of this, one of the proposed standards has a passage to the effect that "function calls may set errno to arbitrary values, as long as their effect on errno is _not_ documented". In other words, don't check errno after calling a library routine unless the manual says that it sets errno to something meaningful. Sigh. Alexis Dimitriadis -- _______________________________________________ As soon as I get a full time job, the opinions expressed above will attach themselves to my employer, who will never be rid of them again. alexis @ reed ...teneron! \ ...seismo!ihnp4! - tektronix! - reed.UUCP ...decvax! /