home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c:16664 comp.unix.questions:13513
- Path: sparky!uunet!usc!elroy.jpl.nasa.gov!swrinde!emory!sol.ctr.columbia.edu!spool.mu.edu!olivea!charnel!sifon!thunder.mcrcim.mcgill.edu!mouse
- From: mouse@thunder.mcrcim.mcgill.edu (der Mouse)
- Newsgroups: comp.lang.c,comp.unix.questions
- Subject: Re: name of file descriptor
- Message-ID: <1992Nov17.125931.7731@thunder.mcrcim.mcgill.edu>
- Date: 17 Nov 92 12:59:31 GMT
- References: <1992Nov16.122835.16126@alf.uib.no>
- Followup-To: comp.unix.questions
- Organization: McGill Research Centre for Intelligent Machines
- Lines: 26
-
- In article <1992Nov16.122835.16126@alf.uib.no>, singg@alf.uib.no (Kurt George Gjerde) writes:
-
- > How can I get the filename from a filedescriptor, on Unix??
-
- This is a UNIX question, not a C question, and I'm therefore
- crossposting to comp.unix.questions and redirecting followups there.
-
- In general, you can't. The file descriptor may not be connected to a
- file (it may be a pipe or (other) socket or TLI stream or a device or
- maybe something else). Even if it is a file, the file may have no
- names any longer, or it may have multiple names. Even if it has at
- least one name, there may be no name by which it is accessible to your
- process or possibly even other processes. And even if you assume it
- has a name that you could use to refer to it by, there is no way to
- find any such name short of a full scan of all filesystems, which can
- take a *long* time.
-
- You're usually best off writing wrappers for open/close (or
- fopen/fclose if you're using stdio) that remember filenames. The major
- case where this doesn't work is when you're dealing with redirection to
- or from files, in which case you're pretty much out of luck.
-
- der Mouse
-
- mouse@larry.mcrcim.mcgill.edu
-