Quote Originally Posted by nonoob View Post
Normally you should only check errno if something went wrong... like a function returned:

fopen() returned a NULL
fwrite() returned a count written which was not what was intended
rename() returned non zero
mkdir() return non zero

... and deal with the consequences right then. Not after a function was completed. The way I do it anyhow.
There are some library functions where negative (or NULL) return values are permitted, and are not errors. The only way to check in that case whether an error occurred is to examine errno (first setting it to zero before calling the function).