When an error occurs in one of the UNIX System functions, a negative value is often returned, and the integer
errno
is set to a value, that gives additional information. -- Advanced Programming in the UNIX Environment, section 1.7
This seems weird:
- It introduces coupling between different compilation units of the standard library - error states are not defined in the modules causing them.
- It introduces implementation complexity, because
errno
needs to be thread local. - It introduces usability complexity because the user needs to check that the original system call is in error, and then check
errno
Which is also another function call.
Why not encode the error states in the return values?