zephyr: Introduce `errno.h`-compatible ranges for subsystems
Error numbers in Zephyr depend on the C library being used, but a script ensures that the minimal libc errno.h always matches the corresponding newlib errno.h. In fact, newlib defines a starting point for a user-defined range.
The proposal here would be to allow subsystems to reserve ranges of the int returned on almost every Zephyr function so errno.h in order to provide subsystem-specific error codes, like so:
#define ERRNO_BT_BEGIN 0x1000
#define ERR_BT_FAILED_TO_PAIR ERRNO_BT_BEGIN+1
#define ERRNO_WIFI_BEGIN 0x2000
#define ERR_WIFI_WPA_ERROR ERRNO_WIFI_BEGIN+1
...
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 17 (9 by maintainers)
Would it be best to leave errno to libc and encourage a different error reporting mechanism in Zephyr APIs?
It is somewhat helpful to make them globally unique; it makes debugging code paths that expect errno to be set when it isn’t (and errno is left with some previous value). And, you can implement strerror too. However, that latter is a lot easier to implement if error numbers are dense and managed in a single place. A modest process for allocating new errno values across the whole system that encouraged unifying common definitions across subsystems could work here?
I’m not sure it matters if errno values are the same across C libraries, as long as the whole system uses the C library errno.h file and not a Zephyr errno file.