Skip to content

Commit

Permalink
tools: bpftool: move p_err() and p_info() from main.h to common.c
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
qmonnet authored and davem330 committed Nov 5, 2017
1 parent 8a3b718 commit 0b1c27d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
31 changes: 31 additions & 0 deletions tools/bpf/bpftool/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,37 @@

#include "main.h"

void p_err(const char *fmt, ...)
{
va_list ap;

va_start(ap, fmt);
if (json_output) {
jsonw_start_object(json_wtr);
jsonw_name(json_wtr, "error");
jsonw_vprintf_enquote(json_wtr, fmt, ap);
jsonw_end_object(json_wtr);
} else {
fprintf(stderr, "Error: ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
}
va_end(ap);
}

void p_info(const char *fmt, ...)
{
va_list ap;

if (json_output)
return;

va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
va_end(ap);
}

static bool is_bpffs(char *path)
{
struct statfs st_fs;
Expand Down
34 changes: 3 additions & 31 deletions tools/bpf/bpftool/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ extern const char *bin_name;
extern json_writer_t *json_wtr;
extern bool json_output;

void p_err(const char *fmt, ...);
void p_info(const char *fmt, ...);

bool is_prefix(const char *pfx, const char *str);
void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep);
void usage(void) __attribute__((noreturn));
Expand All @@ -97,35 +100,4 @@ int prog_parse_fd(int *argc, char ***argv);
void disasm_print_insn(unsigned char *image, ssize_t len, int opcodes);
void print_hex_data_json(uint8_t *data, size_t len);

static inline void p_err(const char *fmt, ...)
{
va_list ap;

va_start(ap, fmt);
if (json_output) {
jsonw_start_object(json_wtr);
jsonw_name(json_wtr, "error");
jsonw_vprintf_enquote(json_wtr, fmt, ap);
jsonw_end_object(json_wtr);
} else {
fprintf(stderr, "Error: ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
}
va_end(ap);
}

static inline void p_info(const char *fmt, ...)
{
va_list ap;

if (json_output)
return;

va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
va_end(ap);
}

#endif

0 comments on commit 0b1c27d

Please sign in to comment.