Xref: utzoo comp.unix.questions:12009 comp.unix.xenix:5203 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!sun!pitstop!sundc!seismo!uunet!auspex!guy From: guy@auspex.UUCP (Guy Harris) Newsgroups: comp.unix.questions,comp.unix.xenix Subject: Re: How to determine file being redirected to in C Keywords: redirection Message-ID: <1111@auspex.UUCP> Date: 3 Mar 89 09:33:47 GMT References: <10@sherpa.UUCP> <169@usource.UUCP> Reply-To: guy@auspex.UUCP (Guy Harris) Distribution: na Organization: Auspex Systems, Santa Clara Lines: 16 >One way which comes to mind (this might be the hard way) is >to use stat() on the file and fstat() on stdout. The only "easier" way might be to open the file first and do an "fstat" on it as well; it's probably slightly more efficient. >Then you compare st_ino and st_dev in both returned structures. If both >sets match (ie r.st_ino == f.st_ino && r.st_dev == f.st_dev) >then they must be the same file. (Network fans: is this true >for remotely-mounted filesystems?) It's true of the SunOS NFS implementation, and probably on all NFS implementations derived from it. The AT&T S5R3 RFS implementation looks as if it attempts to preserve this property, also. Any file system implementation that *doesn't* preserve that property is broken; POSIX quite explicitly says that "st_dev" and "st_ino" uniquely identify a file.