Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site stl.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!allegra!bellcore!decvax!genrad!panda!talcott!harvard!seismo!mcvax!ukc!stc-a!stl!jlm
From: jlm@stl.UUCP (John Messenger)
Newsgroups: net.unix-wizards
Subject: Is this a pipe, fstat(), and seeking on pipes
Message-ID: <129@stl.UUCP>
Date: Wed, 27-Feb-85 10:29:13 EST
Article-I.D.: stl.129
Posted: Wed Feb 27 10:29:13 1985
Date-Received: Sat, 2-Mar-85 03:55:21 EST
Organization: STL,Harlow,UK.
Lines: 35

[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 
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.