Re: how to get the file name
- From: John Fusco <fusco_john@xxxxxxxxx>
- Date: Sat, 07 Jan 2006 02:03:54 GMT
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)
It's a horrible kludge, and only works on linux, but ...
FILE fp = ... int fd = fileno(fp); sprintf(procbuf,"/proc/self/fd/%d",fd) readlink(procbuf,filenamebuf,sizeof(filenamebuf))
ref. readlink(2), fileno(3)
John .
- Follow-Ups:
- Re: how to get the file name
- From: Rich Walker
- Re: how to get the file name
- References:
- how to get the file name
- From: marsarden
- Re: how to get the file name
- From: "Nils O. Selåsdal"
- 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
|