How to get file_name with file *?

In my class, I have a FILE* ascii_file; data element FILE* ascii_file; , which is always initialized using the class constructor. How can I get the full path to asci_file ? I don’t want to store more information about expect ascii_file and want it to work on windows, linux and solaris.

+5
source share
2 answers

This task will require non-portable code.

On Windows, you can convert FILE* to a CRT file descriptor using _ fileno , and then convert to an OS descriptor using _ get_osfhandle .

Then you can get the file name as shown here (using file association).

Retrieving file name from file handle

+4
source

Here is a solution for Linux:

Getting file name from file descriptor in C

+4
source

Source: https://habr.com/ru/post/919100/


All Articles