[net.bugs.4bsd] isatty

hamilton (09/20/82)

#N:uicsovax:2200006:000:695
uicsovax!hamilton    Sep 17 18:44:00 1982

isatty() uses gtty() to determine whether a file is a tty.  it works fine,
but when the file is not a tty, the global errno gets set.  this can
confuse some autodiagnostic functions (eg perror) that get called for
non-syscall related errors.  i propose the following slightly modified
isatty.c:

    /* @(#)isatty.c	4.1 (Berkeley) 12/21/80 */
    /*
     * Returns 1 iff file is a tty
     */

    #include <sgtty.h>
    extern int errno;

    isatty (f)
    {
	    register int save_errno = errno;
	    struct sgttyb ttyb;

	    if (gtty(f, &ttyb) < 0) {
		    errno = save_errno;
		    return(0);
	    }
	    return(1);
    }

	wayne hamilton ({ucbvax,harpo}!pur-ee!uiucdcs!uicsovax!hamilton)