B
Ben Pfaff
hilz said:I have a FILE pointer that points to a file on disk (not any other io
stream). is there a way to get the filename of that FILE?
Not portably.
hilz said:I have a FILE pointer that points to a file on disk (not any other io
stream). is there a way to get the filename of that FILE?
hilz said:I have a FILE pointer that points to a file on disk
(not any other I/O stream).
is there a way to get the filename of that *FILE?
No.
I thought it would be the _tmpfname part of the struct,
but it doesn't look like it
stream). is there a way to get the filename of that FILE?
i thought it would be the _tmpfname part of the struct, but it doesn't look
like it
Gordon Burditt said:This is highly system-dependent and likely very expensive. On some
systems, you can do a file-tree walk, stat() each file looking for
one with a matching device and inode numbers. BUT: there's no
guarantee that a file still has a name. (unlinking an open file
is not guaranteed to destroy the file). There's no guarantee that
a file has only one name (even if you don't follow symlinks). And
even if it does have a name, there's no guarantee that you have
permission to use it or even determine it. And, of course, there's
no guarantee that your system even HAS stat(), symlinks, device
numbers, inode numbers, opendir(), readdir(), or unlink().
File-tree walks on some systems (particularly large news servers
with terabytes of storage) can take days. This is not something
you want to do lightly.
If you fopen()ed the file yourself, SAVE THE NAME if you're going
to need it. If the FILE in question is stdin, stdout, or stderr,
maybe the program interface should be changed so you supply a
filename instead.
Gordon L. Burditt
hilz said:In addition, I am working exclusively with Window$ where there is only one
file with that name and path.
does that make it possible now?
chances at a useful response.
The problem is that the FILE pointer is supplied to me by a third party
function that i have no control over, and there is no way i can get the name
from anywhere else. So unfortunately, i cannot "SAVE THE NAME".
In addition, I am working exclusively with Window$ where there is only one
file with that name and path.
does that make it possible now?
hilz said:I have a FILE pointer that points to a file on disk (not any other
io stream). is there a way to get the filename of that FILE?
i thought it would be the _tmpfname part of the struct, but it
doesn't look like it
>
> i thought this was more of a C question than a Windows question.
> If not, i appologize.
The problem is that the FILE pointer is supplied to me by a third party
function that i have no control over, and there is no way i can get the name
from anywhere else. So unfortunately, i cannot "SAVE THE NAME".
In addition, I am working exclusively with Window$ where there is only one
file with that name and path.
does that make it possible now?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.