f



File name from file description

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

0
poddar007 (16)
3/28/2006 8:08:20 PM
comp.unix.programmer 10848 articles. 0 followers. kokososo56 (350) is leader. Post Follow

2 Replies
817 Views

Similar Articles

[PageSpeed] 7

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
0
iso
3/28/2006 9:02:21 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

0
Fletcher
3/28/2006 9:08:18 PM
Reply: