Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!killer!ames!ncar!boulder!sunybcs!bingvaxu!leah!itsgw!steinmetz!uunet!mcvax!philmds!leo From: leo@philmds.UUCP (Leo de Wit) Newsgroups: comp.unix.wizards Subject: Re: Getting the pathname from a FILE*. Message-ID: <560@philmds.UUCP> Date: 9 Jul 88 21:02:32 GMT References: <651@umb.umb.edu> Reply-To: leo@philmds.UUCP (Leo de Wit) Organization: Philips I&E DTS Eindhoven Lines: 26 In article <651@umb.umb.edu> karl@umb.umb.edu (Karl Berry.) writes: > >The title says it all. Am I missing something obvious? >The pathname doesn't seem to be a field in either the >_iobuf or the structure returned by stat. >ttyname or ctermid will give you the pathname >of your terminal, but I want the pathname of an >arbitrary FILE* I have fopen. Or am I missing some >reason why this is not feasible? This is not trivial. Think for instance of multiple links to a file (either hard or symbolic links); which name will you use? Or what if one of the directories in the path has multiple links - apart from the trivial ones (for example /usr/include/sys, which on our system == /usr/sys/h) ? Or what if the FILE * is connected to a pipe? Or what if the file is already gone (i.e. unlinked but still open) ? VMS has a function for it: fgetname(). On Unix you could fstat the file descriptor (the char _file member from the _iobuf struct). This gives you the inode number; now go look for the filename(s). What is the use? If you have opened the file, you used the filename already (unless the open file is inherited from a parent process). Leo.