tags:

views:

57

answers:

2

Assume I have a file pointer FILE* myfile. Is there a way to retrieve the name of the file where myfile is reading from or writing to?

+1  A: 

Not in any CRT implementation that I've ever seen. It is useless info, you already have to supply the file name to get a FILE*. You could probably dig an operating system handle out of the FILE structure although you might need to hop through a file descriptor table. Your next problem is then the operating system support you'd need to map a file handle back to a file name. That should be difficult too.

Hans Passant
A: 

I found a nice example that uses an overwritten struct MyFile: How to get filename from a FILE*

Simon Linder