xref: /linux/tools/lib/bpf/str_error.c (revision 7fcfa9a2d9a7c1b428d61992c2deaa9e37a437b0)
1 // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2 #undef _GNU_SOURCE
3 #include <string.h>
4 #include <stdio.h>
5 #include "str_error.h"
6 
7 /*
8  * Wrapper to allow for building in non-GNU systems such as Alpine Linux's musl
9  * libc, while checking strerror_r() return to avoid having to check this in
10  * all places calling it.
11  */
12 char *libbpf_strerror_r(int err, char *dst, int len)
13 {
14 	int ret = strerror_r(err, dst, len);
15 	if (ret)
16 		snprintf(dst, len, "ERROR: strerror_r(%d)=%d", err, ret);
17 	return dst;
18 }
19