aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/bpf/libbpf.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/lib/bpf/libbpf.c')
-rw-r--r--tools/lib/bpf/libbpf.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index c08d6bca1c22..6f0c13a1fb3c 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -7,8 +7,48 @@
7 */ 7 */
8 8
9#include <stdlib.h> 9#include <stdlib.h>
10#include <stdio.h>
11#include <stdarg.h>
12#include <string.h>
10#include <unistd.h> 13#include <unistd.h>
11#include <asm/unistd.h> 14#include <asm/unistd.h>
12#include <linux/bpf.h> 15#include <linux/bpf.h>
13 16
14#include "libbpf.h" 17#include "libbpf.h"
18
19#define __printf(a, b) __attribute__((format(printf, a, b)))
20
21__printf(1, 2)
22static int __base_pr(const char *format, ...)
23{
24 va_list args;
25 int err;
26
27 va_start(args, format);
28 err = vfprintf(stderr, format, args);
29 va_end(args);
30 return err;
31}
32
33static __printf(1, 2) libbpf_print_fn_t __pr_warning = __base_pr;
34static __printf(1, 2) libbpf_print_fn_t __pr_info = __base_pr;
35static __printf(1, 2) libbpf_print_fn_t __pr_debug;
36
37#define __pr(func, fmt, ...) \
38do { \
39 if ((func)) \
40 (func)("libbpf: " fmt, ##__VA_ARGS__); \
41} while (0)
42
43#define pr_warning(fmt, ...) __pr(__pr_warning, fmt, ##__VA_ARGS__)
44#define pr_info(fmt, ...) __pr(__pr_info, fmt, ##__VA_ARGS__)
45#define pr_debug(fmt, ...) __pr(__pr_debug, fmt, ##__VA_ARGS__)
46
47void libbpf_set_print(libbpf_print_fn_t warn,
48 libbpf_print_fn_t info,
49 libbpf_print_fn_t debug)
50{
51 __pr_warning = warn;
52 __pr_info = info;
53 __pr_debug = debug;
54}