Possible Duplicate:
Getting Filename from file descriptor in C
Is there a simple and (reasonably) portable way of getting the filename from a FILE*
?
I open a file using f = fopen(filename, ...)
and then pass down f
to various other functions, some of which may report an error. I'd like to report the filename in the error message but avoid having to pass around the extra parameter.
I could create a custom wrapper struct { FILE *f, const char *name }
, but is there perhaps a simpler way? (If the FILE*
wasn't opened using fopen
I don't care about the result.)