Xref: utzoo comp.unix.questions:31901 comp.unix.programmer:1972 Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!stanford.edu!leland.Stanford.EDU!dkeisen From: dkeisen@leland.Stanford.EDU (Dave Eisen) Newsgroups: comp.unix.questions,comp.unix.programmer Subject: Re: How do I tell if STDIN is a PIPE? Message-ID: <1991Jun3.141144.23620@leland.Stanford.EDU> Date: 3 Jun 91 14:11:44 GMT References: <1991May26.172328.713@arizona.edu> <1991May30.101153.27842@thunder.mcrcim.mcgill.edu> <653@eskimo.celestial.com> Distribution: world,local Organization: Sequoia Peripherals, Inc. Lines: 28 In article <653@eskimo.celestial.com> nanook@eskimo.celestial.com (Robert Dinse) writes: > How do I tell whether stdin is coming from a pipe? >> In article <1991May26.172328.713@arizona.edu>, jjr@ace.ece.arizona.edu (Jeffrey J. Rodriguez) writes: > > Try: > fstat(0, &s); > if(s.st_mode & S_IFIFO) > printf("Stdin is a pipe.\n"); > else > printf("Stdin is not a pipe.\n"); This doesn't work everywhere, in particular, it doesn't work on the machine I am posting from. s.st_mode & S_IFREG (which, by the way, is what you should be testing for) is 0 when stdin is a pipe. This doesn't seem to be consistently done across Unices. That is one of the reasons I suggested that the original poster just try his seek and see what happens --- as far as I know, any UNIX asked to seek on a file type that is unseekable will fail with errno set to ESPIPE. -- Dave Eisen dkeisen@leland.Stanford.EDU 1101 San Antonio Road, Suite 102 Mountain View, CA 94043 (415) 967-5644