Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cmcl2!rutgers!clyde!watmath!mks!tj From: tj@mks.UUCP (T. J. Thompson) Newsgroups: comp.unix.questions Subject: Re: distinguishing from pipes and files Message-ID: <320@mks.UUCP> Date: Mon, 23-Nov-87 08:35:59 EST Article-I.D.: mks.320 Posted: Mon Nov 23 08:35:59 1987 Date-Received: Thu, 26-Nov-87 20:46:48 EST References: <454@rocksanne.UUCP> Organization: Mortice Kern Systems, Waterloo, Ont. Lines: 31 Keywords: files, pipes Summary: possible, but probably a bad idea In article <454@rocksanne.UUCP>, fuss@rocksanne.UUCP (William Fuss) writes: > Can a process can recognize the "source" of its input/output ??? > for example, given the scenerio below: > (1) > foo < input > file2 && bar < file2 > file3 && foobar < file3 > output > (2) > cat input | foo | bar | foobar > output > > Can "bar" figure out that its standard input is coming from: > > a file in example (1), > vs > a pipe in example (2), lseek(0, 0L, 1) will return -1 with errno set to ESPIPE if standard input is a pipe, and succeed if standard input is a regular file. I am sure many people will be ready to point this out. What i wonder is why you want to know the difference. I strongly suggest that any program which behaves differently when its standard input is redirected from a file rather than piped is mis-designed. The only counter-example that springs to mind is a file pager that allows backward scrolling, so copies its input to a temporary file if coming from a pipe (which behaviour is reasonable, being invisible to the user). -- ll // // ,'/~~\' T. J. Thompson uunet!watmath!mks!tj /ll/// //l' `\\\ Mortice Kern Systems Inc. (519) 884-2251 / l //_// ll\___/ 35 King St. N., Waterloo, Ont., Can. N2J 2W9 O_/ Do not void where prohibited