Path: utzoo!attcan!uunet!husc6!mailrus!ames!umd5!mimsy!aplcen!osiris!guest From: guest@osiris.UUCP (Guest account) Newsgroups: comp.unix.wizards Subject: Re: Getting the pathname from a FILE*. Keywords: abusing your data structures Message-ID: <1645@osiris.UUCP> Date: 10 Jul 88 16:30:54 GMT References: <651@umb.umb.edu> <4531@csli.STANFORD.EDU> Organization: Johns Hopkins Hospital Lines: 31 In article <4531@csli.STANFORD.EDU> gandalf@csli.stanford.edu (Juergen Wagner) writes: >The _iobuf structure as defined inincludes a component _file >which is supposed to hold the file descriptor number. *PLEASE* - if you are going to do things like using internal elements of "standard" libraries, try to access them in a more or less "standard" way. Most stdio libraries I've seen have a macro (but could be func, I guess) called fileno(myfd) - which returns just the information you are referring to. This way, your code won't break if someone does something cute or clever to the stdio library and include files. >fstat(fd, &statbuf) gives information about the open file descriptor, so >you can find out the device the inode is on, the inode's number, and a >few other attributes of interest. With that you should be able to find >out the information wanted by looking at the st_mode field (check the >fd type), and eventually by walking through the file system the inode is >on. Does this work if the file system is NFSsed, or something like that ? It almost seems to me that this is a case which stdio is not designed to handle. So - I'd say add another level of indirection. Write a routine that acts like fopen() - and one that acts like fclose(), etc. Have it store the name someplace, using only the "standard" interface to stdio, and then write another routine, or macro, that allows you to get the information back. I can't imagine that would be hard, and I expect it will work a LOT faster than reading your file system. Then again, maybe I don't understand what you're trying to do. 'V'.