how can I get filename from file descriptor?

Perry Hutchison perry at ccssrv.UUCP
Sat Aug 26 09:04:44 AEST 1989


In article <9353 at chinet.chi.il.us> les at chinet.chi.il.us
(Leslie Mikesell) writes:

>What I had in mind was the magic involved in certain open()/close()
>routines.  Suppose you are a cpio-like program that wants to handle
>multiple volumes.  How can you do that if some other program (the
>shell) has opened the device via redirection?  What if you want to
>do a verify pass on a tape device where the only way to rewind is
>to close() and open()?  What if you need to twiddle the handshake
>lines on a tty device?  What if you want to send EOF to something
>on the other end of a FIFO without losing the ability to send more
>data later?  It's all magic and you need the name of the file for
>the incantations.

Another case is in messages concerning I/O errors, which really ought
to include the name of the file.

Meanwhile, in article <2385 at auspex.auspex.com> guy at auspex.auspex.com
(Guy Harris) writes:

>Of course, if it just saved the file name away, it would give you the
>wrong answer if the file were unlinked or renamed after it was opened
> [ discussion of complications ]
>It's not clear that all this would be worth the cost.

For error-message purposes, as well as for Leslie's examples (which seem
to involve special files and FIFO's, which are rarely renamed or removed)
the name originally passed to open should suffice.  To allow for changes
of cwd, the absolute pathname could be saved during open.

Granted that now and then the saved name may no longer be accurate, I
still think that it would be more user-helpful than no info at all.



More information about the Comp.unix.wizards mailing list