Xref: utzoo comp.unix.questions:11941 comp.unix.xenix:5164 Path: utzoo!attcan!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 Message-ID: <1102@auspex.UUCP> Date: 1 Mar 89 20:01:23 GMT References: <10@sherpa.UUCP> <2775@daisy.UUCP> Reply-To: guy@auspex.UUCP (Guy Harris) Distribution: na Organization: Auspex Systems, Santa Clara Lines: 15 >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. In *any* UNIX worth of the name, you can do that; I know of none so feeble-minded that they don't allow that. >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. It's certainly almost enough for "cat", since all it cares about is whether any of the input files are the same as the output file or not. The inode number isn't enough, however; you also need the file system identifier, which is in the "st_dev" field. If two files have the same "st_dev" and "st_ino", they're the same file, otherwise not.