Get file name from file pointer in C

Possible duplicate:
Getting file name from file descriptor in C
How to get file_name with file *?

Is there a way to find filename from a file pointer in C?

fp = fopen(file,"r"); 

From fp, is it possible to get the file name that I opened?

+2
source share
2 answers

I do not believe it, because the file * may be something that does not even have a name. Maybe it depends on the platform, depending on me. Your system, therefore, if you do not care about portability, try looking at the definition of your FILE compiler, if any. Most likely, your only way is to keep the name when you open it.

There are other potentially dangerous ways - check this link:

http://bytes.com/topic/c/answers/218921-how-get-get-filename-file-pointer

Hurrah!

+2
source

See here why this is complicated, and cannot be done in a portable way.

http://discuss.fogcreek.com/joelonsoftware5/default.asp?cmd=show&ixPost=179112

0
source

Source: https://habr.com/ru/post/919098/


All Articles