gcc (GCC) 4.7.2
c89
Is it possible for check if a file has already closed?
I have opened a file using fopen()
and closed using fclose(fd)
.
This file gets opened and closed during the running of the program. However, the user can terminate the program by doing a ctrl-c
.
When I go to my cleanup routine, I don't know if the file is in a open or closed state. So if I try and do a fclose(fd)
twice, it will stack dump.
Some ideas I have been throwing around:
- Add a state to the file to be either opened or closed, and then check that state, means more work for such a simple job.
- Don't do anything as the OS will cleanup automatially when the program ends.
- Is there is the access function, but that will just checks the mode.
Many thanks in advance,