Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How get fileName having FILE*?

Tags:

c++

c

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.

like image 949
Mihran Hovsepyan Avatar asked Nov 29 '10 15:11

Mihran Hovsepyan


1 Answers

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

like image 68
Steve Townsend Avatar answered Sep 20 '22 13:09

Steve Townsend