Given a filehandle is there a way of getting the filename of the file that the handle points to. The program will be running in protected mode DOS as it will be linked in with a Clipper application.
There's no straightforward standard way to do this. First, check your particular implementation's definition of a FILE. They're allowed to put whatever they want in there. If for some reason it actually has a field for the filename, use that (I'm not sure if it's common for there to be such a field or not, but I've never seen it in any implementation I've looked at).
Otherwise, if you really need it to be passed around with the structure, you'd have to make a struct type called NamedFile or something to that effect, and put a FILE* and a char* in there. Write a wrapper for open that initializes both of these, and pass around NamedFile* instead of FILE*.
Note that the above method only knows the name used to open the file. In UNIX, a file could feasibly have several "names". This, by the way, is probably part of the reason the feature you're looking for doesn't exist in a standard way.
The only other thing I can think of is to simply have the filename inside the file as the first line. Seek to the beginning and read the first sequence of characters any time you want to know the name. This requires that you format your files accordingly, of course.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.