Re: how to get the file name



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)

.



Relevant Pages

  • Re: how to get the file name
    ... Tim Keck wrote: ... char * getfilename; ... Remember the filename when you opened it, ... (though linux has some not always reliable way, ...
    (comp.os.linux.development.apps)
  • Re: how to get the file name
    ... Nils O. Selåsdal wrote: ... char * getfilename; ... Remember the filename when you opened it, ... (though linux has some not always reliable way, ...
    (comp.os.linux.development.apps)
  • Re: how to get the file name
    ... Nils O. Selåsdal wrote: ... char * getfilename; ... Remember the filename when you opened it, ... (though linux has some not always reliable way, ...
    (comp.os.linux.development.apps)
  • Re: [9fans] Wearables
    ... I considered using Plan 9, ... Linux. ... I'm not really looking forward to dealing with rio at the very low resolutions ... The idea of window management on such a display, ...
    (comp.os.plan9)
  • Re: [9fans] Help for home user discovering Plan 9
    ... The Plan9 project started in 1980, took around 9 years to be solid ... or Linux came into ... I use 4 or 5 operating systems ... One of them is Plan 9. ...
    (comp.os.plan9)