2 * This bit indicates whether a number is considered a system error code.
3 * If yes, the system errno is just the result of clearing this bit from
6 #define SYSTEM_ERROR_BIT 30
8 /** Check whether the system error bit is set. */
9 #define IS_SYSTEM_ERROR(num) (!!((num) & (1 << SYSTEM_ERROR_BIT)))
11 /** Set the system error bit for the given number. */
12 #define ERRNO_TO_ERROR(num) ((num) | (1 << SYSTEM_ERROR_BIT))
15 _ERROR(SUCCESS, "success") \
16 _ERROR(SYNTAX, "syntax error") \
17 _ERROR(LOOP_COMPLETE, "loop complete") \
18 _ERROR(HASH_TABLE_OVERFLOW, "hash table too small") \
19 _ERROR(BAD_UID, "uid not found in hash table") \
20 _ERROR(ATOI_OVERFLOW, "value too large") \
21 _ERROR(STRTOLL, "unknown strtoll error") \
22 _ERROR(ATOI_NO_DIGITS, "no digits found in string") \
23 _ERROR(ATOI_JUNK_AT_END, "further characters after number") \
24 _ERROR(EMPTY, "file empty") \
25 _ERROR(MMAP, "mmap error") \
26 _ERROR(OSL, "osl error") \
30 * This is temporarily defined to expand to its first argument (prefixed by
31 * 'E_') and gets later redefined to expand to the error text only
33 #define _ERROR(err, msg) E_ ## err,
39 #define _ERROR(err, msg) msg,
40 #define DEFINE_ERRLIST char *adu_errlist[] = {ALL_ERRORS}
43 extern char *adu_errlist[];
47 * adu's version of strerror(3).
49 * \param num The error number.
51 * \return The error text of \a num.
53 static inline const char *adu_strerror(int num)
57 fprintf(stderr, "osl error %d\n", osl_errno & 0xff);
58 assert(osl_errno > 0);
59 return osl_strerror((osl_errno));
61 if (IS_SYSTEM_ERROR(num))
62 return strerror((num) & ((1 << SYSTEM_ERROR_BIT) - 1));
63 return adu_errlist[num];
67 * Wrapper for osl library calls.
69 * This should be used for all calls to osl functions that return an osl error
70 * code. It changes the return value to \p -E_OSL appropriately so that it can
71 * be used for printing the correct error message.
73 * \return \a ret if \a ret >= 0, \p -E_OSL otherwise.
75 static inline int osl(int ret)