Is this a pipe, fstat(), and seeking on pipes

John Messenger jlm at stl.UUCP
Thu Feb 28 01:29:13 AEST 1985


[4.2 BSD VAX 750 - you know, the one that gives mc tbuf par fault panics]

Friends,
When is a descriptor a pipe, and when is it a file?  I have programs
which read (for instance) stdin, and want to know whether they are dealing
with a pipe or not.  One way to do this is to attempt a seek, and see
if you get an error.  However, using the following program:

#include <errno.h>
main() { if (lseek(0,1,1) < 0) perror("lseek"); }
I get:
a.out
	(nothing - all ok)
a.out < a.out
	(nothing - all ok)
cat a.out | a.out
	lseek: Invalid argument (that is, EINVAL)

where I would expect to get lseek: Invalid seek (that is, ESPIPE).

What I really need of course is something that tells me what my
descriptor describes.  Why doesn't fstat() do this?  My manual says
that fstat() on a pipe reports an ordinary file with an i-node number,
restricted permissions, and a not necessarily meaningful length.
Should it really do such a (seemingly perverse) thing?

Seeking *forward* on pipes seems to me a reasonable thing to do.  What
is the general opinion on this?

Sorry if this is another of the "perennial" topics that have been well
dealt with before - I'm hoping it will stand another airing for the
benefit of us "newcomers".
----------------------------------------------------------------------
John Messenger - mcvax!ukc!stl!jlm.



More information about the Comp.unix.wizards mailing list