1 /* SPDX-License-Identifier: GPL-3.0-only */
4 TF_ERROR(SUCCESS, "success"), \
5 TF_ERROR(ATOI_OVERFLOW, "value too large"), \
6 TF_ERROR(ATOI_NO_DIGITS, "no digits found in string"), \
7 TF_ERROR(ATOI_JUNK_AT_END, "further characters after number"), \
8 TF_ERROR(LOPSUB, "lopsub error"), \
9 TF_ERROR(REGEX, "regular expression error"), \
10 TF_ERROR(TXP, "tag expression parse error"), \
11 TF_ERROR(LH_EXIST, "item already exists in hash table"), \
14 * This is temporarily defined to expand to its first argument (prefixed by
15 * 'E_') and gets later redefined to expand to the error text only
17 #define TF_ERROR(err, msg) E_ ## err
18 enum tf_error_codes {TF_ERRORS};
20 #define TF_ERROR(err, msg) msg
21 #define DEFINE_TF_ERRLIST char *tf_errlist[] = {TF_ERRORS}
23 extern char *tf_errlist[];
26 * This bit indicates whether a number is considered a system error number
27 * If yes, the system errno is just the result of clearing this bit from
30 #define SYSTEM_ERROR_BIT 30
32 /** Check whether the system error bit is set. */
33 #define IS_SYSTEM_ERROR(num) (!!((num) & (1 << SYSTEM_ERROR_BIT)))
35 /** Set the system error bit for the given number. */
36 #define ERRNO_TO_TF_ERROR(num) ((num) | (1 << SYSTEM_ERROR_BIT))
38 static inline char *tf_strerror(int num)
41 if (IS_SYSTEM_ERROR(num))
42 return strerror((num) & ((1 << SYSTEM_ERROR_BIT) - 1));
44 return tf_errlist[num];