1 /* SPDX-License-Identifier: GPL-2.0 */
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(TXP, "tag expression parse error"), \
9 TF_ERROR(REGEX, "regular expression error"), \
10 TF_ERROR(LOPSUB, "lopsub error"), \
13 * This is temporarily defined to expand to its first argument (prefixed by
14 * 'E_') and gets later redefined to expand to the error text only
16 #define TF_ERROR(err, msg) E_ ## err
17 enum tf_error_codes {TF_ERRORS};
19 #define TF_ERROR(err, msg) msg
20 #define DEFINE_TF_ERRLIST char *tf_errlist[] = {TF_ERRORS}
22 extern char *tf_errlist[];
25 * This bit indicates whether a number is considered a system error number
26 * If yes, the system errno is just the result of clearing this bit from
29 #define SYSTEM_ERROR_BIT 30
31 /** Check whether the system error bit is set. */
32 #define IS_SYSTEM_ERROR(num) (!!((num) & (1 << SYSTEM_ERROR_BIT)))
34 /** Set the system error bit for the given number. */
35 #define ERRNO_TO_TF_ERROR(num) ((num) | (1 << SYSTEM_ERROR_BIT))
37 static inline char *tf_strerror(int num)
40 if (IS_SYSTEM_ERROR(num))
41 return strerror((num) & ((1 << SYSTEM_ERROR_BIT) - 1));
43 return tf_errlist[num];