How to determine file being redirected to in C

Arnold D. Robbins {EUCC} arnold at mathcs.emory.edu
Thu Mar 2 03:49:03 AEST 1989


>In article <10 at sherpa.UUCP> rac at sherpa.UUCP (Roger A. Cornelius) writes:
>>  Anyway, can someone tell me how to determine (in C)
>>if output is being redirected, or more precisely, how to determine the
>>file output is being redirected to.  The cat command does this (at

In article <475 at ispi.UUCP> jbayer at ispi.UUCP (Jonathan Bayer) writes:
>Use the stat() and fstat() functions, then compare the inode numbers 
>in the structure.  If they are the same then the two files are identical.

Rather, compare the device and inode numbers, and if both are the same
the two files are really the same file.  Two files on two different
filesystems (i.e. devices) can both have the same inode numbers.
-- 
"Unix is a Registered  | Arnold Robbins -- Emory University Computing Center
Bell of AT&T Trademark | DOMAIN: arnold at unix.cc.emory.edu		
Laboratories."         | UUCP: gatech!emory!arnold	PHONE:	+1 404 727-7636
        -- Donn Seeley | BITNET: arnold at emoryu1		FAX:	+1 404 727-2599



More information about the Comp.unix.questions mailing list