Re: how to get the file name



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.
.




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
    ... char * getfilename; ... Remember the filename when you opened it, ... (though linux has some not always reliable way, ... plan 9 added the fd2path system call, ...
    (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: Which programming method is better?
    ... process("standard input", stdin, flags) ... and not a filename argument. ... preincrement argv first. ... I'd also go with const char* instead of char*, ...
    (comp.lang.c)
  • Re: "system" with [ ] in filename
    ... In a perl script I do this: ... Or should I look for the problem in the way Windows handles the in the filename? ... Come over and you make it work on Linux. ... I do not see your code where you transform/read/determine the filename to be written, but a simple routine to make it entirely unique - without the "" would not be out of the question here and would solve the overall problem - giving you time for submitting a bug report to the *magick folks. ...
    (comp.lang.perl.misc)