From 2535ba7006f22a6470f4c88ea7d30c343a1d8799 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Thu, 28 Sep 2017 17:17:45 +0200 Subject: src: get rid of printf This patch introduces nft_print()/nft_gmp_print() functions which have to be used instead of printf to output information that were previously send to stdout. These functions print to a FILE pointer defined in struct output_ctx. It is set by calling: | old_fp = nft_ctx_set_output(ctx, new_fp); Having an application-defined FILE pointer is actually quite flexible: Using fmemopen() or even fopencookie(), an application gains full control over what is printed and where it should go to. Signed-off-by: Eric Leblond Signed-off-by: Phil Sutter Signed-off-by: Pablo Neira Ayuso --- src/fib.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'src/fib.c') diff --git a/src/fib.c b/src/fib.c index b3488aff..21bc69a9 100644 --- a/src/fib.c +++ b/src/fib.c @@ -60,32 +60,33 @@ static const char *fib_result_str(enum nft_fib_result result) return "unknown"; } -static void __fib_expr_print_f(unsigned int *flags, unsigned int f, const char *s) +static void __fib_expr_print_f(unsigned int *flags, unsigned int f, + const char *s, struct output_ctx *octx) { if ((*flags & f) == 0) return; - printf("%s", s); + nft_print(octx, "%s", s); *flags &= ~f; if (*flags) - printf(" . "); + nft_print(octx, " . "); } static void fib_expr_print(const struct expr *expr, struct output_ctx *octx) { unsigned int flags = expr->fib.flags & ~NFTA_FIB_F_PRESENT; - printf("fib "); - __fib_expr_print_f(&flags, NFTA_FIB_F_SADDR, "saddr"); - __fib_expr_print_f(&flags, NFTA_FIB_F_DADDR, "daddr"); - __fib_expr_print_f(&flags, NFTA_FIB_F_MARK, "mark"); - __fib_expr_print_f(&flags, NFTA_FIB_F_IIF, "iif"); - __fib_expr_print_f(&flags, NFTA_FIB_F_OIF, "oif"); + nft_print(octx, "fib "); + __fib_expr_print_f(&flags, NFTA_FIB_F_SADDR, "saddr", octx); + __fib_expr_print_f(&flags, NFTA_FIB_F_DADDR, "daddr", octx); + __fib_expr_print_f(&flags, NFTA_FIB_F_MARK, "mark", octx); + __fib_expr_print_f(&flags, NFTA_FIB_F_IIF, "iif", octx); + __fib_expr_print_f(&flags, NFTA_FIB_F_OIF, "oif", octx); if (flags) - printf("0x%x", flags); + nft_print(octx, "0x%x", flags); - printf(" %s", fib_result_str(expr->fib.result)); + nft_print(octx, " %s", fib_result_str(expr->fib.result)); } static bool fib_expr_cmp(const struct expr *e1, const struct expr *e2) -- cgit v1.2.3