Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!rutgers!cmcl2!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn ) Newsgroups: comp.unix.questions Subject: Re: How to determine file being redirected to in C Keywords: redirection Message-ID: <9745@smoke.BRL.MIL> Date: 28 Feb 89 04:28:28 GMT References: <10@sherpa.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 17 In article <10@sherpa.UUCP> rac@sherpa.UUCP (Roger A. Cornelius) writes: >... 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 >least the Xenix version of cat, I don't think the BSD version does), What "cat" actually does is compare the device/inode numbers for equality; it cannot determine "the" filename because there may not be one, or it may be ambiguous (and would be expensive to figure out anyway). The device/inode numbers are obtained from the fstat() system call. These days, the system ID should also be compared. To determine a filename, assuming you can, for the inode behind a given file descriptor, is a tedious process. Your best bet is to find another solution to whatever your problem is.