Is there a way for a function receiving a value of type FILE *
to get the open mode used on the call to fopen()
used to create the stream?
This question was motivated by the need to extend a C++ class that works as a wrapper to stdio's FILE
pointers, in a way that I can clone an already open stream into a new wrapped one, while the original would continue to be used unwrapped by other parts of the program.
Under POSIX, I know that I can use fileno()
to get the stream's underlying file descriptor in order to clone (dup()
) it, but using the underlying descriptor's file flags would not be an exact replacement for the stream open mode, since it is possible that the stream would have stricter access restrictions than the descriptor it's bound to. So, do you have any suggestions?