5

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.

Mihran Hovsepyan
  • 10,810
  • 14
  • 61
  • 111

2 Answers2

4

Here is a solution for Linux:

Getting Filename from file descriptor in C

Community
  • 1
  • 1
Nucc
  • 1,031
  • 6
  • 20
4

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

Steve Townsend
  • 53,498
  • 9
  • 91
  • 140