Bug in isatty (all systems!)

Joel West jww at sdcsvax.UUCP
Wed Jul 10 10:15:32 AEST 1985


> The following short C program
> 
> main(){
> 	extern int errno;
> 
> 	errno = 0;
> 	putchar('\n');
> 	if(errno > 0)
> 		perror("perror");
> }
> 
> gives unexpected results.
> The reason is that putchar calls putc calls _flsbuf calls isatty
> and isatty contains the code
> 	if(ioctl(f,TIOCGETP,&ttyb)<0)
> 		return(0);

(which sets errno=25: not a typewriter unless stdout is /dev/tty)

I was going to post this one myself.  I found it on BSD 4.2, 
System V/2.0 and UTX-32 (a Gould BSD + V port).  It really
screwed me up bad.

The other 'gotcha' (same systems) is mktemp, which attempts
to build a unique file name.  errno is always 2 (file not
found) after successfully calling mktemp on these 3 systems.



More information about the Comp.unix.wizards mailing list