How to determine file being redirected to in C

Ken Lee klee at daisy.UUCP
Tue Feb 28 11:38:45 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.

In BSD UNIX, you can fstat(2) stdout to determine if the output is a
file or terminal (or whatever) and, what inode number it has.  Since
several file names can have the same inode, you can't tell exactly
what file name was specified, but the inode number should be enough
information for cat and other such applications.

Ken Lee
-- 
klee at daisy.uucp
Daisy Systems Corp., Interactive Graphics Tools Dept.



More information about the Comp.unix.questions mailing list