1 // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
12 /* make sure libbpf doesn't use kernel-only integer typedefs */
13 #pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
16 * Wrapper to allow for building in non-GNU systems such as Alpine Linux's musl
17 * libc, while checking strerror_r() return to avoid having to check this in
18 * all places calling it.
20 char *libbpf_strerror_r(int err
, char *dst
, int len
)
22 int ret
= strerror_r(err
< 0 ? -err
: err
, dst
, len
);
23 /* on glibc <2.13, ret == -1 and errno is set, if strerror_r() can't
24 * handle the error, on glibc >=2.13 *positive* (errno-like) error
25 * code is returned directly
31 /* strerror_r() doesn't recognize this specific error */
32 snprintf(dst
, len
, "unknown error (%d)", err
< 0 ? err
: -err
);
34 snprintf(dst
, len
, "ERROR: strerror_r(%d)=%d", err
, ret
);
39 const char *errstr(int err
)
41 static __thread
char buf
[12];
47 case -E2BIG
: return "-E2BIG";
48 case -EACCES
: return "-EACCES";
49 case -EADDRINUSE
: return "-EADDRINUSE";
50 case -EADDRNOTAVAIL
: return "-EADDRNOTAVAIL";
51 case -EAGAIN
: return "-EAGAIN";
52 case -EALREADY
: return "-EALREADY";
53 case -EBADF
: return "-EBADF";
54 case -EBADFD
: return "-EBADFD";
55 case -EBUSY
: return "-EBUSY";
56 case -ECANCELED
: return "-ECANCELED";
57 case -ECHILD
: return "-ECHILD";
58 case -EDEADLK
: return "-EDEADLK";
59 case -EDOM
: return "-EDOM";
60 case -EEXIST
: return "-EEXIST";
61 case -EFAULT
: return "-EFAULT";
62 case -EFBIG
: return "-EFBIG";
63 case -EILSEQ
: return "-EILSEQ";
64 case -EINPROGRESS
: return "-EINPROGRESS";
65 case -EINTR
: return "-EINTR";
66 case -EINVAL
: return "-EINVAL";
67 case -EIO
: return "-EIO";
68 case -EISDIR
: return "-EISDIR";
69 case -ELOOP
: return "-ELOOP";
70 case -EMFILE
: return "-EMFILE";
71 case -EMLINK
: return "-EMLINK";
72 case -EMSGSIZE
: return "-EMSGSIZE";
73 case -ENAMETOOLONG
: return "-ENAMETOOLONG";
74 case -ENFILE
: return "-ENFILE";
75 case -ENODATA
: return "-ENODATA";
76 case -ENODEV
: return "-ENODEV";
77 case -ENOENT
: return "-ENOENT";
78 case -ENOEXEC
: return "-ENOEXEC";
79 case -ENOLINK
: return "-ENOLINK";
80 case -ENOMEM
: return "-ENOMEM";
81 case -ENOSPC
: return "-ENOSPC";
82 case -ENOTBLK
: return "-ENOTBLK";
83 case -ENOTDIR
: return "-ENOTDIR";
84 case -ENOTSUPP
: return "-ENOTSUPP";
85 case -ENOTTY
: return "-ENOTTY";
86 case -ENXIO
: return "-ENXIO";
87 case -EOPNOTSUPP
: return "-EOPNOTSUPP";
88 case -EOVERFLOW
: return "-EOVERFLOW";
89 case -EPERM
: return "-EPERM";
90 case -EPIPE
: return "-EPIPE";
91 case -EPROTO
: return "-EPROTO";
92 case -EPROTONOSUPPORT
: return "-EPROTONOSUPPORT";
93 case -ERANGE
: return "-ERANGE";
94 case -EROFS
: return "-EROFS";
95 case -ESPIPE
: return "-ESPIPE";
96 case -ESRCH
: return "-ESRCH";
97 case -ETXTBSY
: return "-ETXTBSY";
98 case -EUCLEAN
: return "-EUCLEAN";
99 case -EXDEV
: return "-EXDEV";
101 snprintf(buf
, sizeof(buf
), "%d", err
);