Path: utzoo!attcan!uunet!mailrus!uflorida!travis!brad From: brad@SSD.CSD.HARRIS.COM (Brad Appleton) Newsgroups: comp.lang.c Subject: Re: How do you tell if stdin/stdout is a terminal? Summary: use isatty() (assuming you are on a UNIX system) Keywords: stdin/stdout, unix, C, redirected I/O Message-ID: <613@travis.csd.harris.com> Date: 6 Aug 90 15:32:20 GMT References: <12210@hydra.gatech.EDU> <2072@bimacs.BITNET> Sender: news@travis.csd.harris.com Organization: Harris Computers Systems Division, Fort Lauderdale,FL Lines: 36 In article <2072@bimacs.BITNET> kfir@bimacs.biu.ac.il.UUCP (Yuval Kfir) writes: (stuff deleted) >I seem to remember a function called isatty(stdin). I am not sure it is >standard. I hope this helps. ^^^^^ > Thats almost correct, the usage should be: isatty(STDIN); where you have the following #defines #define STDIN 0 #define STDOUT 1 #define STDERR 2 You need to give it the file-descriptor number, not the file pointer! Some compilers have the above #defines in their standard header files, some dont! Also, On some Unix implementations (you will have to check yours), calling isatty() can set errno to a non-zero value if isatty() returns FALSE. This is due to the fact that some implementations of isatty() use ioctl() to make a terminal-specific setting, if ioctl() fails, the file-descriptor is NOT connected to a terminal. Anyway, if you are on UNIX, isatty() is the way to go. If you are on another system - look through your C-Compiler manual! Hope this helps!! Just for the record - Peter Da Silva helped me figure out why errno was being set! ______________________ "And miles to go before I sleep." ______________________ Brad Appleton brad@travis.ssd.csd.harris.com Harris Computer Systems ...!uunet!hcx1!brad Fort Lauderdale, FL USA ~~~~~~~~~~~~~~~~~~~~ Disclaimer: I said it, not my company! ~~~~~~~~~~~~~~~~~~~