Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cca!mirror!ima!haddock!karl From: karl@haddock.ISC.COM (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: Perror complication Message-ID: <1019@haddock.ISC.COM> Date: Mon, 31-Aug-87 10:51:17 EDT Article-I.D.: haddock.1019 Posted: Mon Aug 31 10:51:17 1987 Date-Received: Fri, 4-Sep-87 05:23:45 EDT References: <8913@brl-adm.ARPA> <8048@mimsy.UUCP> <18005@amdcad.AMD.COM> <301@ncrcan.UUCP> <18082@amdcad.AMD.COM> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 45 Summary: Fix isatty() In article <18082@amdcad.AMD.COM> rpw3@amdcad.UUCP (Rob Warnock) writes: [explanation of the "Not a typewriter" syndrome] I avoid this problem by using my own copy of isatty(); one which does not have the side effect of setting errno. Lately I've noticed some official versions of isatty() have also fixed this. If yours doesn't, help yourself to the PD implementation below. (Actually, the one I keep in my libhack.a is from an assembler version.) Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint ---- cut here ---- #!/bin/sh cat <<\! >bool.h typedef int bool; #define YES 1 #define NO 0 ! cat <<\! >isatty.c /* Test whether a file descriptor is a terminal; preserve errno */ #include "bool.h" #ifdef USG #include #define ioarg struct termio #define ISATTY TCGETA #else #include #define ioarg struct sgttyb #define ISATTY TIOCGETP #endif extern int ioctl(); bool isatty(f) int f; { extern int errno; ioarg dummy; register int saverrno = errno; if (ioctl(f, ISATTY, &dummy) < 0) { errno = saverrno; return (NO); } else { return (YES); } } ! exit 0