file name from file pointer? 
Author Message
 file name from file pointer?

        Is it possible for a function which is passed an open
FILE pointer to get the name of the file that it points to?

--
World's Greatest Living Poster



Wed, 24 Jan 2001 03:00:00 GMT  
 file name from file pointer?
 >   Is it possible for a function which is passed an open
 > FILE pointer to get the name of the file that it points to?

You need to fstat the file to get the st_ino and st_dev that uniquely
identifies the file in the system. You then need to check which file
systems are monted to find the good one, and then you can use find to
look at the good inode in the file system.

For an open fd, you can find 1, 2 or more names for a given file.
You can also find no file name (for example the files created by
tmpfile).

man fstat
man find
man mount

--

--------------------------------------------------------------------
ric Lvnez              "Felix qui potuit rerum cognoscere causas"

(NeXTMail, MIME)                                   Georgica, II-489
--------------------------------------------------------------------



Thu, 25 Jan 2001 03:00:00 GMT  
 file name from file pointer?


Quote:
>        Is it possible for a function which is passed an open
>FILE pointer to get the name of the file that it points to?

In C the answer is no. Under Unix the answer is still no, although you
can scan the filesystem to see if there are any links to the file (Unix
doesn't make a file name an inherent property of a file; 0, 1 or many
links can refer to a particular file and none need corresponds to the name
originally used to open the file, if one was). Attempting to determine a
filename from a FILE pointer almost always indicates that you are
approaching the problem the wrong way.

--
-----------------------------------------


-----------------------------------------



Thu, 25 Jan 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Reading a file name from a text file

2. Can't Read File Unless I Change File Name

3. file name from FILE *

4. Get file name from a *FILE

5. Generating files with sequential file name automatically.

6. cpp __FILE__ with uppercase file names

7. Get File Names of Selected Files

8. get file name from FILE * ?

9. CFileDialog in XP not return the file name in shorcut file(.lnk)

10. File->New in doc/view doesn't clear doc file name

11. What is file name of dragged file?

12. How to use CreateProcess to open a long-file-name file with winword

 

 
Powered by phpBB® Forum Software