Can I retrieve information about a file previously opened with fopen()
using only the pointer it returned?
The reason I ask is that I am trying to write a RAII-style wrapper class for FILE *
s, and I want to make it as general as possible, and one of the functions I imagined for it was a copy-like operation, that would take a FILE *
as an argument, and create a new reference to the same file.
Under POSIX, I can create a duplicate of a file descriptor with dup()
/dup2()
, and even get how the file is being accessed with fnctl()
's F_GETFL
operation. However, even if I do that to the underlying descriptor of a FILE *
, it isn't enough for guessing properties such as if the stream is text or binary (under POSIX, there no real difference, but I want to be general), or its orientation towards char
- or wchar_t
-based text.
So, is there is a way of learning about the stream I'm about to create a wrapper for, how far can I go, and how should I do it?
Thank you for you attention.