diff options
| author | Andre Noll <maan@tuebingen.mpg.de> | 2018-01-11 23:40:23 +0100 |
|---|---|---|
| committer | Andre Noll <maan@tuebingen.mpg.de> | 2018-01-11 23:40:23 +0100 |
| commit | b95de7e4b629c3ffb90ae09b53d0178285e73629 (patch) | |
| tree | 2929492fa05274fc150e09c4821dbf52a65149f3 /err.h | |
initialinitial
Diffstat (limited to 'err.h')
| -rw-r--r-- | err.h | 45 |
1 files changed, 45 insertions, 0 deletions
@@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#define TF_ERRORS \ + TF_ERROR(SUCCESS, "success"), \ + TF_ERROR(ATOI_OVERFLOW, "value too large"), \ + TF_ERROR(ATOI_NO_DIGITS, "no digits found in string"), \ + TF_ERROR(ATOI_JUNK_AT_END, "further characters after number"), \ + TF_ERROR(TXP, "tag expression parse error"), \ + TF_ERROR(REGEX, "regular expression error"), \ + TF_ERROR(LOPSUB, "lopsub error"), \ + +/* + * This is temporarily defined to expand to its first argument (prefixed by + * 'E_') and gets later redefined to expand to the error text only + */ +#define TF_ERROR(err, msg) E_ ## err +enum tf_error_codes {TF_ERRORS}; +#undef TF_ERROR +#define TF_ERROR(err, msg) msg +#define DEFINE_TF_ERRLIST char *tf_errlist[] = {TF_ERRORS} + +extern char *tf_errlist[]; + +/** + * This bit indicates whether a number is considered a system error number + * If yes, the system errno is just the result of clearing this bit from + * the given number. + */ +#define SYSTEM_ERROR_BIT 30 + +/** Check whether the system error bit is set. */ +#define IS_SYSTEM_ERROR(num) (!!((num) & (1 << SYSTEM_ERROR_BIT))) + +/** Set the system error bit for the given number. */ +#define ERRNO_TO_TF_ERROR(num) ((num) | (1 << SYSTEM_ERROR_BIT)) + +static inline char *tf_strerror(int num) +{ + assert(num > 0); + if (IS_SYSTEM_ERROR(num)) + return strerror((num) & ((1 << SYSTEM_ERROR_BIT) - 1)); + else + return tf_errlist[num]; +} + |
