Use ferror()
rather than errno
to check whether an error has occurred on a file stream (after a long string chain of stdio
calls, for example). The ferror()
function tests the error indicator for a specified stream and returns nonzero if and only if the error indicator is set for the stream.
...