Code which writes to files and doesn't check for errors on close is subtly incorrect, although my understanding is that kernel devs bend over backwards to make failure unlikely, probably because everybody does it incorrectly anyway.
Not that it matters, but fclose() doesn't happen in the kernel, so the kernel devs can't do anything about it. All libcs have essentially the same implementation:
- is fp NULL or already already closed? return error
- call fflush() and return error if it fails (fflush also happens in userland, it does a seek() then a write() of the userland buffer)
- call close() and return error if it fails
close() follows essentially the same process inside the kernel: check fd is valid, call flush() (this time truly to disk), close it.
Comments
If closing a file fails then you treat it the same as how you would treat a write failure:
Code which writes to files and doesn't check for errors on close is subtly incorrect, although my understanding is that kernel devs bend over backwards to make failure unlikely, probably because everybody does it incorrectly anyway.Not that it matters, but fclose() doesn't happen in the kernel, so the kernel devs can't do anything about it. All libcs have essentially the same implementation:
- is fp NULL or already already closed? return error
- call fflush() and return error if it fails (fflush also happens in userland, it does a seek() then a write() of the userland buffer)
- call close() and return error if it fails
close() follows essentially the same process inside the kernel: check fd is valid, call flush() (this time truly to disk), close it.