Fix spelling of member of struct num_format.
[adu.git] / error.h
1 /*
2 * Copyright (C) 2008 Andre Noll <maan@tuebingen.mpg.de>
3 *
4 * Licensed under the GPL v2. For licencing details see COPYING.
5 */
6
7 /** \file error.h \brief Error handling functions and macros. */
8
9 /**
10 * This bit indicates whether a number is considered a system error code.
11 * If yes, the system errno is just the result of clearing this bit from
12 * the given number.
13 */
14 #define SYSTEM_ERROR_BIT 30
15
16 /** Check whether the system error bit is set. */
17 #define IS_SYSTEM_ERROR(num) (!!((num) & (1 << SYSTEM_ERROR_BIT)))
18
19 /** Set the system error bit for the given number. */
20 #define ERRNO_TO_ERROR(num) ((num) | (1 << SYSTEM_ERROR_BIT))
21
22 /** The list of all adu error codes with descriptions. */
23 #define ALL_ERRORS \
24 _ERROR(SUCCESS, "success") \
25 _ERROR(SYNTAX, "syntax error") \
26 _ERROR(LOOP_COMPLETE, "loop complete") \
27 _ERROR(HASH_TABLE_OVERFLOW, "hash table too small") \
28 _ERROR(BAD_UID, "uid not found in hash table") \
29 _ERROR(ATOI_OVERFLOW, "value too large") \
30 _ERROR(STRTOLL, "unknown strtoll error") \
31 _ERROR(ATOI_NO_DIGITS, "no digits found in string") \
32 _ERROR(ATOI_JUNK_AT_END, "further characters after number") \
33 _ERROR(EMPTY, "file empty") \
34 _ERROR(MMAP, "mmap error") \
35 _ERROR(OSL, "osl error") \
36 _ERROR(SIGACTION, "could not install signal handler") \
37 _ERROR(OUTPUT, "error writing output") \
38 _ERROR(MALFORMED_FORMAT, "malformed format string") \
39 _ERROR(BAD_ALIGN_SPEC, "bad alignment specifier") \
40 _ERROR(TRAILING_GARBAGE, "trailing garbage after specifier") \
41 _ERROR(UNIT, "no unit allowed here") \
42 _ERROR(BAD_UNIT, "invalid unit specifier") \
43 _ERROR(BAD_ATOM, "invalid atom") \
44 _ERROR(BAD_OUTPUT_ARG, "invalid name for output") \
45 _ERROR(REGEX, "regular expression error") \
46 _ERROR(MKDIR, "could not create directory")
47
48
49 /**
50 * This is temporarily defined to expand to its first argument (prefixed by
51 * 'E_') and gets later redefined to expand to the error text only
52 */
53 #define _ERROR(err, msg) E_ ## err,
54
55 /**
56 * \cond (doxygen can not handle multiple definitions of the same macro).
57 *
58 * This just creates an enum consisting of the first argument of the above
59 * error list.
60 */
61 enum error_codes {
62 ALL_ERRORS
63 };
64 #undef _ERROR
65
66 /*
67 * Here we define the array of error texts used by adu_strerror().
68 */
69 #define _ERROR(err, msg) msg,
70 #define DEFINE_ERRLIST char *adu_errlist[] = {ALL_ERRORS}
71 /** \endcond */
72
73 extern int osl_errno;
74
75 /** Contains the description of all adu error codes. */
76 extern char *adu_errlist[];
77
78 extern const char *adu_strerror(int num);
79
80 /**
81 * Wrapper for osl library calls.
82 *
83 * \param ret The return value of an osl library function.
84 *
85 * This should be used for all calls to osl functions that return an osl error
86 * code. It changes the return value to \p -E_OSL appropriately so that it can
87 * be used for printing the correct error message.
88 *
89 * \return \a ret if \a ret >= 0, \p -E_OSL otherwise.
90 */
91 _static_inline_ int osl(int ret)
92 {
93 if (ret >= 0)
94 return ret;
95 osl_errno = -ret;
96 return -E_OSL;
97 }