Mail Archives: djgpp-workers/2003/03/02/06:37:06
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 <stdio.h>
#include <unistd.h>
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. <sigh>
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/ ]
- Raw text -