How do I tell if STDIN is a PIPE?

Len Reed lbr at holos0.uucp
Wed May 29 03:24:56 AEST 1991


In article <1991May26.172328.713 at arizona.edu> jjr at ace.ece.arizona.edu (Jeffrey J. Rodriguez) writes:
>How do I tell whether stdin is coming from a pipe?

Use isapipe(0).

>My problem is that lseek & fseek won't work with a pipe.

Sure, but if you could check the error return from lseek.  The isapipe()
routine is cleaner, though.

>If stdin is coming from a pipe, then what is the best way to do a seek?

You can't. :-)

>If the input data is not ASCII, then a loop of getchar() won't work.

You are asking how can you move forward in the file from the current point.
So who says getchar() won't work?  It'll read binary bytes with no problem.
-- 
Len Reed
Holos Software, Inc.
Voice: (404) 496-1358
UUCP: ...!gatech!holos0!lbr



More information about the Comp.unix.questions mailing list