'errno vs errors returned by library functions

For errno, there are a bunch of library functions, like strerror(), etc. to convert or print the error code.

But what about the error codes returned by library functions?

E.g. write() will return EAGAIN, EBADF, etc.

Where do these symbols come from? Are they compatible with strerror() &co?



Solution 1:[1]

EAGAIN, EBADF etc. are symbols for system error numbers, defined in errno.h. They are compatible with strerror and related functions.

Note that write doesn’t return one of these values on error; on error, it returns -1, and sets errno appropriately.

Few functions return error numbers; amusingly enough, one of them is strerror_r, which returns 0 on success, or EINVAL or ERANGE on failure.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Stephen Kitt