No, you have to keep track of it yourself. This is analagous to the question of telling if a pointer to an allocated block has been freed. There could be no way to do such a test because the pointer is no longer valid. The same applies with FILE *
. Once you have closed the file, any attempt to access the underlying object results in undefined behavior.
Updated:
Beware, to quote the Linux man page:
The behaviour of fclose() is undefined if the stream parameter is an illegal pointer, or is a descriptor already passed to a previous invo‐ cation of fclose().
Keep in mind that undefined behavior doesn't mean that it will crash or that it won't "work". It means that no particular behavior is guaranteed and that the operation is unsafe. Accessing a FILE
struct after fclose()
is a very bad idea.