Possible Duplicate:
Getting Filename from file descriptor in C
Obtain filename from file pointer in C
I have a function here:
handle_file(FILE *file)
{
if(condition)
{
print filename and other msg;
}
}
The only thing we know here is the a pointer to the file; is it possible to get the filename according to the pointer?
Check out this answer to obtain file descriptor and this answer to get file name from file descriptor. Should be OK on Linux (not sure about other operating systems).
Here’s a quick working example (tested under Cygwin/Win7):
Output: