This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: FILE Pointer
- From: Muthukumar Ratty <muthu at iqmail dot net>
- To: Michael Meissner <meissner at the-meissners dot org>
- Cc: Muthukumar Ratty <muthu at iqmail dot net>, Eljay Love-Jensen <eljay at adobe dot com>, Bharathi S <bharathi at lantana dot tenet dot res dot in>, GNU GCC <gcc-help at gcc dot gnu dot org>
- Date: Wed, 28 May 2003 09:03:33 -0700 (PDT)
- Subject: Re: FILE Pointer
On Wed, 28 May 2003, Michael Meissner wrote:
> > Look at
> > 1. fileno (3) and
> > 2. getdents (2)
>
> Actually in general this approach has problems. The file pointed to by the
You are right. getdents is not the way to go. (note to myself: dont read
man page after a long day :(
Muthu
> file descriptor may have been deleted, but the file is still available for use
> until the last file descriptor is closed, when the space is recovered. If the
> file is not deleted, there is no guarantee that it is located in the current
> directory (getdents uses a file descriptor of a directory, not a plain file,
> and is what ls uses), so you will need to walk the entire filesystem to look
> for the file. Finally with hardlinks, there may be more than one name for the
> file.
>
> If you need a name for a file descriptor under Linux, and you have the /proc
> filesystem mounted, you can always use:
>
> char *fname (FILE *stream) {
> static char name[256];
> sprintf (name, "/proc/%d/fd/%d", getpid (), fileno (stream));
> return name;
> }
>
>