1 // SPDX-License-Identifier: LGPL-2.1
6 #include "event-parse.h"
9 #define _PE(code, str) str
10 static const char * const tep_error_str[] = {
16 * The tools so far have been using the strerror_r() GNU variant, that returns
17 * a string, be it the buffer passed or something else.
19 * But that, besides being tricky in cases where we expect that the function
20 * using strerror_r() returns the error formatted in a provided buffer (we have
21 * to check if it returned something else and copy that instead), breaks the
22 * build on systems not using glibc, like Alpine Linux, where musl libc is
25 * So, introduce yet another wrapper, str_error_r(), that has the GNU
26 * interface, but uses the portable XSI variant of strerror_r(), so that users
27 * rest asured that the provided buffer is used and it is what is returned.
29 int tep_strerror(struct tep_handle *tep __maybe_unused,
30 enum tep_errno errnum, char *buf, size_t buflen)
39 int err = strerror_r(errnum, buf, buflen);
44 if (errnum <= __TEP_ERRNO__START ||
45 errnum >= __TEP_ERRNO__END)
48 idx = errnum - __TEP_ERRNO__START - 1;
49 msg = tep_error_str[idx];
50 snprintf(buf, buflen, "%s", msg);