Billy Mays said:
In my current situation, I have a file pointer that I do not know the
status. It might still be open or closed. What I'm trying to see is if
there is a way to determine (safely) whether or not an arbitrary file
pointer has already been closed?
There isn't.
Does some internal attribute of the FILE struct itself change to signify
that it is open or closed?
There's no guarantee that FILE is a struct (though it typically is), and
the standard certainly says nothing about its contents.
An implementation could call malloc() to allocate a FILE object in
fopen() and free() to deallocate it in fclose(). in other words,
once you close the file, the FILE object may no longer exist.
fclose() cannot modify the FILE* value that you pass to it, so
after fclose(f), any reference to f invokes undefined behavior.
If you don't need a portable solution, there *might* be a
system-specific way to get the information you want. But note that
given this:
FILE *f0;
FILE *f1;
f0 = fopen("some_path", "r");
fclose(f0);
f1 = fopen("some_other_path", "r");
f1 might point to the same FILE object that f0 pointed to. (In an
experiment I just tried, it did exactly that.)
There *might* be some system-specific way to do this, but most likely
there isn't.
You need to find a way to keep track of whether the file is open
or closed.