summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorQuentin Monnet <quentin.monnet@netronome.com>2017-11-03 16:59:07 -0400
committerDavid S. Miller <davem@davemloft.net>2017-11-05 08:28:51 -0500
commit0b1c27db12fd338ed912fec18f5cc02d7bd4e54e (patch)
tree0dd8caba4edcc1dee3ba8c30b520d57ace8ced45 /tools
parent8a3b718ac2c29abcba8e12636710cff3cee8c01b (diff)
tools: bpftool: move p_err() and p_info() from main.h to common.c
The two functions were declared as static inline in a header file. There is no particular reason why they should be inlined, they just happened to remain in the same header file when they were turned from macros to functions in a precious commit. Make them non-inlined functions and move them to common.c file instead. Suggested-by: Joe Perches <joe@perches.com> Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com> Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'tools')
-rw-r--r--tools/bpf/bpftool/common.c31
-rw-r--r--tools/bpf/bpftool/main.h34
2 files changed, 34 insertions, 31 deletions
diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c
index f0288269dae8..aa7017098b2a 100644
--- a/tools/bpf/bpftool/common.c
+++ b/tools/bpf/bpftool/common.c
@@ -50,6 +50,37 @@
50 50
51#include "main.h" 51#include "main.h"
52 52
53void p_err(const char *fmt, ...)
54{
55 va_list ap;
56
57 va_start(ap, fmt);
58 if (json_output) {
59 jsonw_start_object(json_wtr);
60 jsonw_name(json_wtr, "error");
61 jsonw_vprintf_enquote(json_wtr, fmt, ap);
62 jsonw_end_object(json_wtr);
63 } else {
64 fprintf(stderr, "Error: ");
65 vfprintf(stderr, fmt, ap);
66 fprintf(stderr, "\n");
67 }
68 va_end(ap);
69}
70
71void p_info(const char *fmt, ...)
72{
73 va_list ap;
74
75 if (json_output)
76 return;
77
78 va_start(ap, fmt);
79 vfprintf(stderr, fmt, ap);
80 fprintf(stderr, "\n");
81 va_end(ap);
82}
83
53static bool is_bpffs(char *path) 84static bool is_bpffs(char *path)
54{ 85{
55 struct statfs st_fs; 86 struct statfs st_fs;
diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h
index d315d01be645..ff5ad05b137b 100644
--- a/tools/bpf/bpftool/main.h
+++ b/tools/bpf/bpftool/main.h
@@ -71,6 +71,9 @@ extern const char *bin_name;
71extern json_writer_t *json_wtr; 71extern json_writer_t *json_wtr;
72extern bool json_output; 72extern bool json_output;
73 73
74void p_err(const char *fmt, ...);
75void p_info(const char *fmt, ...);
76
74bool is_prefix(const char *pfx, const char *str); 77bool is_prefix(const char *pfx, const char *str);
75void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep); 78void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep);
76void usage(void) __attribute__((noreturn)); 79void usage(void) __attribute__((noreturn));
@@ -97,35 +100,4 @@ int prog_parse_fd(int *argc, char ***argv);
97void disasm_print_insn(unsigned char *image, ssize_t len, int opcodes); 100void disasm_print_insn(unsigned char *image, ssize_t len, int opcodes);
98void print_hex_data_json(uint8_t *data, size_t len); 101void print_hex_data_json(uint8_t *data, size_t len);
99 102
100static inline void p_err(const char *fmt, ...)
101{
102 va_list ap;
103
104 va_start(ap, fmt);
105 if (json_output) {
106 jsonw_start_object(json_wtr);
107 jsonw_name(json_wtr, "error");
108 jsonw_vprintf_enquote(json_wtr, fmt, ap);
109 jsonw_end_object(json_wtr);
110 } else {
111 fprintf(stderr, "Error: ");
112 vfprintf(stderr, fmt, ap);
113 fprintf(stderr, "\n");
114 }
115 va_end(ap);
116}
117
118static inline void p_info(const char *fmt, ...)
119{
120 va_list ap;
121
122 if (json_output)
123 return;
124
125 va_start(ap, fmt);
126 vfprintf(stderr, fmt, ap);
127 fprintf(stderr, "\n");
128 va_end(ap);
129}
130
131#endif 103#endif