Getting the pathname from a FILE*.

Juergen Wagner gandalf at csli.STANFORD.EDU
Sat Jul 9 13:11:51 AEST 1988


The _iobuf structure as defined in <stdio.h> includes a component _file
which is supposed to hold the file descriptor number. With fdopen() you
can create a FILE* structure from an arbitrary file descriptor (which
may refer to a UNIX file, a socket, or whatsoever), so the FILE* structure
may access something else than a plain UNIX file.

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.

I know, it's a painful procedure but as far as I know, there is no other
way to obtain the information you're looking for, other than by fiddling
around with statbuf.

-- 
Juergen "Gandalf" Wagner,		   gandalf at csli.stanford.edu
Center for the Study of Language and Information (CSLI), Stanford CA



More information about the Comp.unix.wizards mailing list