1

The manpage for close and this http://pubs.opengroup.org/onlinepubs/009695399/functions/close.html (which looks authoritative) say the close system call may fail.

How is an IO library supposed to deal with that?

1

Most worrisome would be

 [EIO]              A previously-uncommitted write(2) encountered an
                    input/output error.

so programs ideally should check the return value of close, especially for EIO. Writes would most often fail if a filesystem fills up, though ideally there would be monitoring or logrotation or such to catch that situation before it happens. Checksumming the data as it is being written then verifying what was written may be necessary if you don't trust the filesystem and are dealing with super critical data, like, I don't know, /etc/passwd or payments batch files, both of which I've seen become horribly corrupted for reasons unrelated to the filesystem filling up.

I'm going to guess that not every program that writes files checks the return, though that would have to be audited on a case-by-case basis. (I recall false positives from I think libxml years ago on close checks?)

I'm also going to duck out on how a C library should do the error handling bit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.