In my class I have 开发者_如何转开发FILE* ascii_file;
data member, which always is initialized via class constructor. How can I get full path of the asci_file
? I don't want to store more information about the file expect ascii_file
, and want it to work on windows, linux and solaris.
This task is going to require non-portable code.
On Windows you can convert FILE*
to CRT file descriptor using _fileno, and then convert to an OS handle using _get_osfhandle.
Then you can get the filename as shown here (using file mapping).
Obtaining a File Name From a File Handle
Here is a solution for Linux:
Getting Filename from file descriptor in C
精彩评论