aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/bpf/str_error.c
diff options
context:
space:
mode:
authorIngo Molnar <mingo@kernel.org>2018-10-08 10:40:34 +0200
committerIngo Molnar <mingo@kernel.org>2018-10-08 10:40:34 +0200
commitedfbeecd92b0c4a648ed96a7e255bfc9a1bc4642 (patch)
treeefdfc57e2520886842a27f2c9978c83d968ba709 /tools/lib/bpf/str_error.c
parentx86/asm: Use CC_SET()/CC_OUT() in __cmpxchg_double() (diff)
parentMerge tag 'char-misc-4.19-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc (diff)
downloadlinux-dev-edfbeecd92b0c4a648ed96a7e255bfc9a1bc4642.tar.xz
linux-dev-edfbeecd92b0c4a648ed96a7e255bfc9a1bc4642.zip
Merge branch 'linus' into x86/asm, to pick up fixes
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'tools/lib/bpf/str_error.c')
-rw-r--r--tools/lib/bpf/str_error.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/tools/lib/bpf/str_error.c b/tools/lib/bpf/str_error.c
new file mode 100644
index 000000000000..b8798114a357
--- /dev/null
+++ b/tools/lib/bpf/str_error.c
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: LGPL-2.1
+#undef _GNU_SOURCE
+#include <string.h>
+#include <stdio.h>
+#include "str_error.h"
+
+/*
+ * Wrapper to allow for building in non-GNU systems such as Alpine Linux's musl
+ * libc, while checking strerror_r() return to avoid having to check this in
+ * all places calling it.
+ */
+char *str_error(int err, char *dst, int len)
+{
+ int ret = strerror_r(err, dst, len);
+ if (ret)
+ snprintf(dst, len, "ERROR: strerror_r(%d)=%d", err, ret);
+ return dst;
+}