Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!yale!cmcl2!adm!smoke!gwyn From: gwyn@smoke.brl.mil (Doug Gwyn) Newsgroups: comp.unix.questions Subject: Re: How do I tell if STDIN is a PIPE? Message-ID: <16281@smoke.brl.mil> Date: 27 May 91 03:26:37 GMT References: <1991May26.172328.713@arizona.edu> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 18 In article <1991May26.172328.713@arizona.edu> jjr@ace.ece.arizona.edu (Jeffrey J. Rodriguez) writes: >How do I tell whether stdin is coming from a pipe? >There must be some system call I can use from a C program. The simplest method is to attempt an lseek(0,0L,1) and see if it reports failure: If you can't seek to relative location 0, the file is undoubtedly not seekable in general. (If you CAN seek to relative location 0, doing so will not mess anything up.) >If stdin is coming from a pipe, then what is the best way to do a seek? There isn't one. >Please let me know if there's a better way to handle this. Why do you think you need to seek? Perhaps what you need to do is copy the standard input into a temporary (regular) file and switch to that instead of trying to use stdin directly.