Re: how to get the file name
- From: "Nils O. Selåsdal" <noselasd@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: 6 Jan 2006 20:07:16 +0100
Måns Rullgård wrote:
"Nils O. Selåsdal" <NOS@xxxxxxx> writes:
Tim Keck wrote:Nils O. Selåsdal wrote:marsarden wrote:
only has the FILE * handle , how to get the file name ?
for example,i have a function accpet a (FILE *)argumment and return the file name : char * getfilename(FILE * fp);You cannot. Remember the filename when you opened it, if you can.
(though linux has some not always reliable way, get the filedescriptor with the fileno() function , call the readlink function on the /proc/self/fd/<fd> fd file. Do a ls -l /proc/self/fd to see what it's about)One of the beauties of the design is that there is a many to one relationship between directory entries and files, so a given file may have many names.All one could do was remember the filename when it's opened. plan 9 added the fd2path system call, where the kernel remembers the original path when it is opened.
What happens if the file is renamed/deleted and replaced with a different file while it is open?
You get the name. What you do with it is your business, if the name later on points to a different file, though luck, or perhaps that's exactly what you expect.
(It should be noted that plan 9 has wildly different sematics for what happens when you delete a file than what unix has)
.
- References:
- how to get the file name
- From: marsarden
- Re: how to get the file name
- From: "Nils O. Selåsdal"
- Re: how to get the file name
- From: Tim Keck
- Re: how to get the file name
- From: "Nils O. Selåsdal"
- Re: how to get the file name
- From: Måns Rullgård
- how to get the file name
- Prev by Date: Re: how to get the file name
- Next by Date: Re: how to get the file name
- Previous by thread: Re: how to get the file name
- Next by thread: Re: how to get the file name
- Index(es):
Relevant Pages
|