Reputation: 32805
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?
Upvotes: 2
Views: 112
Reputation: 3438
I found a nice example that uses an overwritten struct MyFile: How to get filename from a FILE*
Upvotes: 0
Reputation: 942267
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.
Upvotes: 1