This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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;
> 	}
>
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]