The libexplain library provides a set of functions that may be used to explain Unix and Linux system call errors. This will make your application's error messages much more understandable to your users.
The library is not quite a drop-in replacement for strerror, but it comes close. Each system call has a dedicated libexplain function, for example
If, for example, you were to try to open
no-such-dir/some-file, the above code would print the following error message:
The above code comes pre-packaged in the form of the explain_open_or_die function. Using this helper function, the code fragment above may be written as:
Helper functions are available for all supported system calls. They come in two varieties:
_on_error. The latter prints the error, but still returns to the caller with the original error code.
The library also provides thread safe function variations.