File name from file description

File name from file description

Post by poddar00 » Thu, 30 Mar 2006 05:08:20


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
 
 
 

File name from file description

Post by Ms Rullg » Thu, 30 Mar 2006 06:02:21


XXXX@XXXXX.COM writes:


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.

--
Ms Rullgd
XXXX@XXXXX.COM

 
 
 

File name from file description

Post by Fletcher G » Thu, 30 Mar 2006 06:08:18


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