how can I get filename from file descriptor?

David Elliott dce at Solbourne.COM
Wed Aug 23 02:58:58 AEST 1989


In article <20482 at sequent.UUCP> paulr at crg3.UUCP (Paul Reger) writes:
>
>The solutions to this problems are very dissatisfying.  I think the
>object oriented approach should be adopted here to file operations.
>What I mean is this:
>
>modify fopen() and the FILE structure in the following ways:
>
>Have the FILE structure have a name field in it:
>
>    char *name;
...

But this doesn't really solve the problem in the general case, and it's
something one can easily implement without changing stdio.  I mean, if
I called fopen() to open the file, I knew the name at some point, and
could have saved it in a table myself.

Most people who ask this question want to know the name of the file
associated with a file descriptor that they inherited via redirection,
in which case the name isn't known, and there may indeed be no name
associated with the file (pipes and unlinked temp files are the
typical examples).

Also, not everyone uses stdio (whether they should or not is a separate
issue).

The reason the solutions are dissatisfying, even after talking about
them for the last 10 years, is that there really isn't a good solution
unless you fundamentally change Unix.

-- 
David Elliott		dce at Solbourne.COM
			...!{uunet,boulder,nbires,sun}!stan!dce

"I had a dream that my kids had been reparented." - Tom LaStrange



More information about the Comp.unix.wizards mailing list