Skip to content

Commit 0b1c27d

Browse files
qmonnetdavem330
authored andcommitted
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 <[email protected]> Signed-off-by: Quentin Monnet <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8a3b718 commit 0b1c27d

File tree

2 files changed

+34
-31
lines changed

2 files changed

+34
-31
lines changed

tools/bpf/bpftool/common.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,37 @@
5050

5151
#include "main.h"
5252

53+
void 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+
71+
void 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+
5384
static bool is_bpffs(char *path)
5485
{
5586
struct statfs st_fs;

tools/bpf/bpftool/main.h

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ extern const char *bin_name;
7171
extern json_writer_t *json_wtr;
7272
extern bool json_output;
7373

74+
void p_err(const char *fmt, ...);
75+
void p_info(const char *fmt, ...);
76+
7477
bool is_prefix(const char *pfx, const char *str);
7578
void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep);
7679
void usage(void) __attribute__((noreturn));
@@ -97,35 +100,4 @@ int prog_parse_fd(int *argc, char ***argv);
97100
void disasm_print_insn(unsigned char *image, ssize_t len, int opcodes);
98101
void print_hex_data_json(uint8_t *data, size_t len);
99102

100-
static 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-
118-
static 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-
131103
#endif

0 commit comments

Comments
 (0)