Pieter
Pieter

Reputation: 32805

Retrieving the name of the file that is associated with a file pointer

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

Answers (2)

Simon Linder
Simon Linder

Reputation: 3438

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

Upvotes: 0

Hans Passant
Hans Passant

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

Related Questions