Home > Archive > Unix Programming > March 2006 > File name from file description
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
File name from file description
|
|
| poddar007@gmail.com 2006-03-28, 10:00 pm |
| Hi,
I am new to this group. I had just one small question
Is it possible to get the file name back from file descriptor.
i.e.
I have written a function to overload the libc write using LD_PRELOAD
my_write(int fd, void *buf, size_t nbytes)
In this function is it possible to find the filename from "fd".
thanks
amit
| |
| Måns Rullgård 2006-03-28, 10:00 pm |
| poddar007@gmail.com writes:
> Hi,
>
> I am new to this group. I had just one small question
>
> Is it possible to get the file name back from file descriptor.
No. There is no such thing as "the filename". On some Unixes you can
get a filename from a file descriptor by various means, but there is
no guarantee that this was the name it was opened with, or that the
name is still valid. You're much better off designing your system in
a way that doesn't need the filename.
--
Måns Rullgård
mru@inprovide.com
| |
| Fletcher Glenn 2006-03-28, 10:00 pm |
| poddar007@gmail.com wrote:
> Hi,
>
> I am new to this group. I had just one small question
>
> Is it possible to get the file name back from file descriptor.
>
> i.e.
>
> I have written a function to overload the libc write using LD_PRELOAD
>
> my_write(int fd, void *buf, size_t nbytes)
>
> In this function is it possible to find the filename from "fd".
>
> thanks
> amit
>
fstat might get you part of the information that you want, but remember,
a file does not necessarily have only one name. The info from fstat
will only identify one name, and not necessarily the name that was
used to open the file.
--
Fletcher Glenn
|
|
|
|
|