Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving the path from a file descriptor or FILE *?

Tags:

c

Is there a way to retrieve path information from a file descriptor or FILE pointer?

I'm aware that this data may not always be relevant/useful for case where the file descriptor is a socket, pipe, etc.

like image 346
tapi Avatar asked Oct 27 '25 02:10

tapi


1 Answers

I don't believe there's any portable way, but e.g. on Linux you can call readlink on "/proc/self/fd/fileno" and the kernel will give you a path if it can, or one of various kinds of funny-looking strings if not.

like image 129
hobbs Avatar answered Oct 29 '25 09:10

hobbs