How do I tell if STDIN is a PIPE?
    Boyd Roberts 
    boyd at prl.dec.com
       
    Tue Jun  4 01:08:51 AEST 1991
    
    
  
In article <1991Jun3.141144.23620 at leland.Stanford.EDU>, dkeisen at leland.Stanford.EDU (Dave Eisen) writes:
>
> >> In article <1991May26.172328.713 at arizona.edu>, jjr at ace.ece.arizona.edu (Jeffrey J. Rodriguez) writes:
> >
> >     Try:
> >	fstat(0, &s);
> >	if(s.st_mode & S_IFIFO)
> >     ...
> 
> This doesn't work everywhere, in particular, it doesn't work on the machine I
> am posting from. s.st_mode & S_IFREG (which, by the way, is what you should
> be testing for) is 0 when stdin is a pipe. This doesn't seem to be consistently
> done across Unices.
> 
You don't test for anything that way.  This:
    if ((sb.st_mode & S_IFMT) == S_IFIFO)
is the way it's done (unless you have those gory POSIX macros).  But,
of course they're not `portable'; except to POSIX.
Boyd Roberts			boyd at prl.dec.com
``When the going gets wierd, the weird turn pro...''
    
    
More information about the Comp.unix.programmer
mailing list