Error Codes
include/err.h View source View on GitHubStructs
Section titled “Structs”err_facility
Section titled “err_facility” struct err_facility (4 fields) source
enum err (18 variants) source
When this enum err is negated, i.e. becomes positive, the upper 16 bits indicate the facility. With 0, it’s just one of these, but if it’s > 0, it came from a specific subsystem that defined a struct err_facility
§
ERR_OK = 0 Success
§
ERR_UNKNOWN = -1 Unknown or unspecified error
§
ERR_NO_MEM = -2 Out of memory
§
ERR_NO_DEV = -3 No such device
§
ERR_NO_ENT = -4 No such file or directory
§
ERR_EXIST = -5 File already exists
§
ERR_IO = -6 I/O error
§
ERR_NOT_DIR = -7 Not a directory
§
ERR_IS_DIR = -8 Is a directory
§
ERR_INVAL = -9 Invalid argument
§
ERR_PERM = -10 Permission denied
§
ERR_FAULT = -11 Bad address
§
ERR_BUSY = -12 Resource/device busy
§
ERR_AGAIN = -13 Try again later
§
ERR_NOT_IMPL = -14 Not implemented
§
ERR_NOSPC = -15 No space left on device
§
ERR_OVERFLOW = -16 Value too large
§
ERR_NOT_EMPTY = -17 Directory not empty
Functions
Section titled “Functions”err_facility_to_str
Section titled “err_facility_to_str”err_facilities_init
Section titled “err_facilities_init”void err_facilities_init(void) source errno_to_str
Section titled “errno_to_str” STRINGIFY_DECLARE(errno_to_str, enum err) (1 declaration) source
Macros
Section titled “Macros”ERR_IS_FATAL
Section titled “ERR_IS_FATAL”#define ERR_IS_FATAL(e) source Expansion
#define ERR_IS_FATAL(e) (e != ERR_OK && e != ERR_AGAIN) ERR_IS_MATCH_1
Section titled “ERR_IS_MATCH_1”#define ERR_IS_MATCH_1(v, a) source Expansion
#define ERR_IS_MATCH_1(v, a) ((v) == (a)) ERR_IS_MATCH_2
Section titled “ERR_IS_MATCH_2”#define ERR_IS_MATCH_2(v, a, b) source Expansion
#define ERR_IS_MATCH_2(v, a, b) (ERR_IS_MATCH_1(v, a) || ((v) == (b))) ERR_IS_MATCH_3
Section titled “ERR_IS_MATCH_3”#define ERR_IS_MATCH_3(v, a, b, c) source Expansion
#define ERR_IS_MATCH_3(v, a, b, c) (ERR_IS_MATCH_2(v, a, b) || ((v) == (c))) ERR_IS_MATCH_4
Section titled “ERR_IS_MATCH_4”#define ERR_IS_MATCH_4(v, a, b, c, d) source Expansion
#define ERR_IS_MATCH_4(v, a, b, c, d) \
(ERR_IS_MATCH_3(v, a, b, c) || ((v) == (d))) ERR_IS_MATCH_5
Section titled “ERR_IS_MATCH_5”#define ERR_IS_MATCH_5(v, a, b, c, d, e) source Expansion
#define ERR_IS_MATCH_5(v, a, b, c, d, e) \
(ERR_IS_MATCH_4(v, a, b, c, d) || ((v) == (e))) ERR_IS_MATCH_6
Section titled “ERR_IS_MATCH_6”#define ERR_IS_MATCH_6(v, a, b, c, d, e, f) source Expansion
#define ERR_IS_MATCH_6(v, a, b, c, d, e, f) \
(ERR_IS_MATCH_5(v, a, b, c, d, e) || ((v) == (f))) ERR_IS_MATCH_7
Section titled “ERR_IS_MATCH_7”#define ERR_IS_MATCH_7(v, a, b, c, d, e, f, g) source Expansion
#define ERR_IS_MATCH_7(v, a, b, c, d, e, f, g) \
(ERR_IS_MATCH_6(v, a, b, c, d, e, f) || ((v) == (g))) ERR_IS_MATCH_8
Section titled “ERR_IS_MATCH_8”#define ERR_IS_MATCH_8(v, a, b, c, d, e, f, g, h) source Expansion
#define ERR_IS_MATCH_8(v, a, b, c, d, e, f, g, h) \
(ERR_IS_MATCH_7(v, a, b, c, d, e, f, g) || ((v) == (h))) ERR_GUARD
Section titled “ERR_GUARD”#define ERR_GUARD(val, ...) source Expansion
#define ERR_GUARD(val, ...) \
({ \
__auto_type _v = (val); \
if (cc_unlikely(_v < 0 && !PP_OVERLOAD(ERR_IS_MATCH, \
__VA_ARGS__)(_v, __VA_ARGS__))) \
panic("unhandled error: %s", errno_to_str(_v)); \
_v; \
}) ERR_CREATE
Section titled “ERR_CREATE”#define ERR_CREATE(pre, del) source Deltas must always be positive
Expansion
#define ERR_CREATE(pre, del) \
({ \
enforce((del & 0xFFFF) == del); \
enforce(del > 0); \
-((((int) (pre)) << 16) | (((int) (del)) & 0xFFFF)); \
}) ERR_GET_FACILITY
Section titled “ERR_GET_FACILITY”#define ERR_GET_FACILITY(e) source Expansion
#define ERR_GET_FACILITY(e) \
({ \
enforce(e < 0); \
((-(e)) >> 16) & 0xFFFF; \
}) ERR_GET_DELTA
Section titled “ERR_GET_DELTA”#define ERR_GET_DELTA(e) source Expansion
#define ERR_GET_DELTA(e) \
({ \
enforce(e < 0); \
((-(e)) & 0xFFFF); \
}) ERR_PREFIX
Section titled “ERR_PREFIX”#define ERR_PREFIX(n) source Expansion
#define ERR_PREFIX(n) ((__err_facility_##n).prefix) ERR_DELTA_START
Section titled “ERR_DELTA_START”#define ERR_DELTA_START (1) source #define ERR(n, d) source Expansion
#define ERR(n, d) ERR_CREATE(ERR_PREFIX(n), d) ERR_PTR_INTERNAL_2
Section titled “ERR_PTR_INTERNAL_2”#define ERR_PTR_INTERNAL_2(n, d) source Expansion
#define ERR_PTR_INTERNAL_2(n, d) ERR_PTR_INTERNAL_1(ERR(n, d)) ERR_PTR_INTERNAL_1
Section titled “ERR_PTR_INTERNAL_1”#define ERR_PTR_INTERNAL_1(e) source Expansion
#define ERR_PTR_INTERNAL_1(e) ((void *) (e)) ERR_PTR
Section titled “ERR_PTR”ERR_FACILITY
Section titled “ERR_FACILITY”#define ERR_FACILITY(n) source Expansion
#define ERR_FACILITY(n) __err_facility_##n ERR_FACILITY_EXTERN
Section titled “ERR_FACILITY_EXTERN”#define ERR_FACILITY_EXTERN(n) source Expansion
#define ERR_FACILITY_EXTERN(n) extern struct err_facility __err_facility_##n ERR_FACILITY_DEFINE
Section titled “ERR_FACILITY_DEFINE”#define ERR_FACILITY_DEFINE(n, ...) source Expansion
#define ERR_FACILITY_DEFINE(n, ...) \
LINKER_SECTION_OBJECT(struct err_facility, err_facilities) \
__err_facility_##n = {.name = #n, __VA_ARGS__} err_checked
Section titled “err_checked”#define err_checked enum err cc_warn_unused_result source Used as a return value to reduce signature length noise