Note: Please read to the end before marking this as duplicate. While it\'s similar, the scope of what I\'m looking for in an answer extends beyond what the
Consider the inverse of your question: "Under what situations can we guarantee that close
will succeed?" The answer is:
close
in this OS and Kernel versionIf you are convinced that you program doesn't have any logic errors and you have complete control over the Kernel and file system, then you don't need to check the return value of close
.
Otherwise, you have to ask yourself how much you care about diagnosing problems with close
. I think there is value in checking and logging the error for diagnostic purposes:
close
, then you'll be able to quickly track it down. This may help to catch a bug early before it causes problems.close
does return an error when (for example) data was not flushed, then you'll be able to quickly diagnose why the data got corrupted. It's an easy red flag because you know the error should not occur.