0001
0002 #undef _GNU_SOURCE
0003 #include <string.h>
0004 #include <stdio.h>
0005
0006 #include "event-parse.h"
0007
0008 #undef _PE
0009 #define _PE(code, str) str
0010 static const char * const tep_error_str[] = {
0011 TEP_ERRORS
0012 };
0013 #undef _PE
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 int tep_strerror(struct tep_handle *tep __maybe_unused,
0030 enum tep_errno errnum, char *buf, size_t buflen)
0031 {
0032 const char *msg;
0033 int idx;
0034
0035 if (!buflen)
0036 return 0;
0037
0038 if (errnum >= 0) {
0039 int err = strerror_r(errnum, buf, buflen);
0040 buf[buflen - 1] = 0;
0041 return err;
0042 }
0043
0044 if (errnum <= __TEP_ERRNO__START ||
0045 errnum >= __TEP_ERRNO__END)
0046 return -1;
0047
0048 idx = errnum - __TEP_ERRNO__START - 1;
0049 msg = tep_error_str[idx];
0050 snprintf(buf, buflen, "%s", msg);
0051
0052 return 0;
0053 }