Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!ucsd!ucbvax!huji.ac.il!amoss From: amoss@huji.ac.il (Amos Shapira) Newsgroups: comp.lang.c Subject: Re: How do you tell if stdin/stdout is a terminal? Keywords: stdin/stdout, unix, C, redirected I/O Message-ID: Date: 6 Aug 90 14:43:48 GMT References: <12210@hydra.gatech.EDU> Sender: daemon@ucbvax.BERKELEY.EDU Lines: 22 Hello, gg10@prism.gatech.EDU (GALLOWAY) writes: >So, how do they do it on a generic unix box? Simple, don't know how much compatible it is, but there should be a routine in the standard C library called "isatty(fd)" which will return 1 if fd (a file descriptor) is a terminal and 0 otherwise. If you don't have isatty(), it's way of operation is simple, it just does an ioctl that only a terminal will accept without an error, like "ioctl(fd, TIOGETP, &junk)" and if it returns a value less than a 0 then fd is not a tty, otherwise it is. Not that it does a "GET*" operation, so it doesn't brake anything. Just for the sake of completeness, to convert from a file pointer (FILE *) to a file descriptor (int), use fileno(fp). Hope this helps, Amos Shapira. amoss@batata.huji.ac.il