Getting the pathname from a FILE*.

Guest account guest at osiris.UUCP
Mon Jul 11 02:30:54 AEST 1988


In article <4531 at csli.STANFORD.EDU> gandalf at csli.stanford.edu (Juergen Wagner) writes:
>The _iobuf structure as defined in <stdio.h> includes 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'.



More information about the Comp.unix.wizards mailing list