Sender: rich AT phekda DOT freeserve DOT co DOT uk Message-ID: <3E61ECD9.232BAE0@phekda.freeserve.co.uk> Date: Sun, 02 Mar 2003 11:36:57 +0000 From: Richard Dawe X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.2.23 i586) X-Accept-Language: de,fr MIME-Version: 1.0 To: djgpp-workers AT delorie DOT com Subject: Re: Some tidy-ups after the changes to isatty [PATCH] References: <10303020302 DOT AA17358 AT clio DOT rice DOT edu> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: djgpp-workers AT delorie DOT com Hello. Charles Sandmann wrote: > > > * Document the new behaviour on the isatty info page. > > > > * Some code assumed isatty(fd) != 0 indicated that fd was a terminal. > > Fix these cases. > > Does POSIX really say that a bad file handle should return -1? If so, > this is inconsistent with every implementation I've ever seen (Turbo C, > old DJGPP, AIX, Solaris, HP/UX). Add Linux to this list. ---Start t-isatty--- #include #include int main (void) { int foo = isatty(99); if (foo < 0) perror("wibble"); else if (foo == 0) puts("Not a TTY"); else puts("A TTY"); return(0); } ---End t-isatty.c--- iolanthe:~/tmp =] !gcc gcc -g -Wall -o t-isatty t-isatty.c iolanthe:~/tmp =] ./t-isatty Not a TTY > Even our example is wrong (which isn't fixed with this patch). All of > the other implementations say it will return 0 and set errno() if > something was wrong. Scary. Just look at all the places in the libc > which need changing. Admittedly a bad handle should be rare, but... [snip] Re-reading SUSv2 and the POSIX draft, it turns out that it doesn't return -1. I don't know where I got that from. I guess I saw "sets errno" and added "and returns -1" mentally. But the previous behaviour was slightly incorrect: it did not set errno. Thanks for catching this. Patch to follow. Bye, Rich =] -- Richard Dawe [ http://www.phekda.freeserve.co.uk/richdawe/ ]