2 * Copyright (C) 2008 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
8 * This bit indicates whether a number is considered a system error code.
9 * If yes, the system errno is just the result of clearing this bit from
12 #define SYSTEM_ERROR_BIT 30
14 /** Check whether the system error bit is set. */
15 #define IS_SYSTEM_ERROR(num) (!!((num) & (1 << SYSTEM_ERROR_BIT)))
17 /** Set the system error bit for the given number. */
18 #define ERRNO_TO_ERROR(num) ((num) | (1 << SYSTEM_ERROR_BIT))
21 _ERROR(SUCCESS, "success") \
22 _ERROR(SYNTAX, "syntax error") \
23 _ERROR(LOOP_COMPLETE, "loop complete") \
24 _ERROR(HASH_TABLE_OVERFLOW, "hash table too small") \
25 _ERROR(BAD_UID, "uid not found in hash table") \
26 _ERROR(ATOI_OVERFLOW, "value too large") \
27 _ERROR(STRTOLL, "unknown strtoll error") \
28 _ERROR(ATOI_NO_DIGITS, "no digits found in string") \
29 _ERROR(ATOI_JUNK_AT_END, "further characters after number") \
30 _ERROR(EMPTY, "file empty") \
31 _ERROR(MMAP, "mmap error") \
32 _ERROR(OSL, "osl error") \
33 _ERROR(SIGNAL_SIG_ERR, "signal() returned SIG_ERR") \
34 _ERROR(OUTPUT, "error writing output") \
35 _ERROR(MALFORMED_FORMAT, "malformed format string") \
36 _ERROR(BAD_ALIGN_SPEC, "bad alignment specifier") \
37 _ERROR(TRAILING_GARBAGE, "trailing garbage after specifier") \
38 _ERROR(UNIT, "no unit allowed here") \
39 _ERROR(BAD_UNIT, "invalid unit specifier") \
40 _ERROR(BAD_ATOM, "invalid atom") \
41 _ERROR(BAD_OUTPUT_ARG, "invalid name for output") \
42 _ERROR(REGEX, "regular expression error")
46 * This is temporarily defined to expand to its first argument (prefixed by
47 * 'E_') and gets later redefined to expand to the error text only
49 #define _ERROR(err, msg) E_ ## err,
55 #define _ERROR(err, msg) msg,
56 #define DEFINE_ERRLIST char *adu_errlist[] = {ALL_ERRORS}
59 extern char *adu_errlist[];
63 * adu's version of strerror(3).
65 * \param num The error number.
67 * \return The error text of \a num.
69 static inline const char *adu_strerror(int num)
73 assert(osl_errno > 0);
74 return osl_strerror((osl_errno));
76 if (IS_SYSTEM_ERROR(num))
77 return strerror((num) & ((1 << SYSTEM_ERROR_BIT) - 1));
78 return adu_errlist[num];
82 * Wrapper for osl library calls.
84 * This should be used for all calls to osl functions that return an osl error
85 * code. It changes the return value to \p -E_OSL appropriately so that it can
86 * be used for printing the correct error message.
88 * \return \a ret if \a ret >= 0, \p -E_OSL otherwise.
90 static inline int osl(int ret)