[physfs] What to do if PHYSFS_close fails?

Sik the hedgehog sik.the.hedgehog at gmail.com
Sat Jun 8 00:07:30 EDT 2013

2013/6/8, Ryan C. Gordon <icculus at icculus.org>:
> Is that true? If it's built on top of Unix open(), then POSIX specifies
> in the case of EIO or EINTR, your file descriptor is undefined at this
> point (which is something worse than a leak...it may or may not be valid
> to try close() again).

The C standard says fclose always gets rid of the stream, even if it
failed to close it. Any attempts to use the FILE pointer will result
in undefined behavior no matter what.

If PhysicsFS assumes that the FILE pointer is still valid when fclose
fails then change that *now*.

> That being said: PHYSFS_close() dictates that the PHYSFS_File* is still
> valid in this case, but I would think the underlying OS handle isn't,
> and it's not like you can will a failing disk to unfail and make the
> PHYSFS_close() call work on a later try.

Ironically, if PHYSFS_close fails, then PHYSFS_deinit will also fail
(since there are files that it can't close). This pretty much means
any shut down will need to be unclean and hope the operating system
clears up everything when the process is killed on exit.

More information about the physfs mailing list