]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
src: remove trailing \n from all nft_*_snprintf functions
authorPablo Neira Ayuso <pablo@netfilter.org>
Thu, 18 Apr 2013 23:51:57 +0000 (01:51 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 18 Apr 2013 23:55:58 +0000 (01:55 +0200)
The caller should add it in case it needs it.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
examples/nft-chain-get.c
examples/nft-rule-get.c
examples/nft-set-elem-get.c
examples/nft-set-get.c
examples/nft-table-get.c
src/chain.c
src/expr/lookup.c
src/rule.c
src/set.c
src/set_elem.c
src/table.c

index b32fc0c9ddc292db666a5b05f1a4f5c254d1cb8b..b8155234730b2b5c91d5ac76a0954795b4fbe96f 100644 (file)
@@ -37,7 +37,7 @@ static int table_cb(const struct nlmsghdr *nlh, void *data)
        }
 
        nft_chain_snprintf(buf, sizeof(buf), t, *type, 0);
-       printf("%s", buf);
+       printf("%s\n", buf);
 
 err_free:
        nft_chain_free(t);
index 2821afe4f9783335162cfd54cbd86406b864bd27..5bf41f56429bfa95420001d3e6d7ad201e6f961a 100644 (file)
@@ -37,7 +37,7 @@ static int table_cb(const struct nlmsghdr *nlh, void *data)
        }
 
        nft_rule_snprintf(buf, sizeof(buf), t, *type, 0);
-       printf("%s", buf);
+       printf("%s\n", buf);
 
 err_free:
        nft_rule_free(t);
index 3c45ead1c2ff9015cb72979fa22560439683d3ab..34dfca2c3062202d2a71ddc92518f57d30ab8df6 100644 (file)
@@ -36,7 +36,7 @@ static int set_cb(const struct nlmsghdr *nlh, void *data)
        }
 
        nft_set_snprintf(buf, sizeof(buf), t, 0, 0);
-       printf("%s", buf);
+       printf("%s\n", buf);
 
 err_free:
        nft_set_free(t);
index a07a1d7459f4834e404bea169824c18171a21037..d4588ba66c029d8ba07f052182a89362a2aa1aef 100644 (file)
@@ -36,7 +36,7 @@ static int set_cb(const struct nlmsghdr *nlh, void *data)
        }
 
        nft_set_snprintf(buf, sizeof(buf), t, 0, 0);
-       printf("%s", buf);
+       printf("%s\n", buf);
 
 err_free:
        nft_set_free(t);
index 518e176f5eccd4017272afd0ba10d3b564538cf3..b11363682e4840fe9d8c33b09036f3b1bfe5e438 100644 (file)
@@ -37,7 +37,7 @@ static int table_cb(const struct nlmsghdr *nlh, void *data)
        }
 
        nft_table_snprintf(buf, sizeof(buf), t, *type, 0);
-       printf("%s", buf);
+       printf("%s\n", buf);
 
 err_free:
        nft_table_free(t);
index c06e5526182db49341b72b648f2d737bf7c3f325..fb5d218f13d1b30aad59a16ebe2311d6446e056b 100644 (file)
@@ -471,7 +471,7 @@ static int nft_chain_snprintf_default(char *buf, size_t size, struct nft_chain *
 {
        return snprintf(buf, size, "family=%u table=%s chain=%s type=%s "
                                   "hook=%u prio=%d policy=%d use=%d "
-                                  "packets=%lu bytes=%lu\n",
+                                  "packets=%lu bytes=%lu",
                        c->family, c->table, c->name, c->type, c->hooknum,
                        c->prio, c->policy, c->use, c->packets, c->bytes);
 }
index 003554b9b39cf246ca78d8471055656365158f51..104661566d1b969abc6ef4f1ea400a41d2ca64a8 100644 (file)
@@ -169,7 +169,7 @@ nft_rule_expr_lookup_snprintf_default(char *buf, size_t size,
 {
        int len = size, offset = 0, ret;
 
-       ret = snprintf(buf, len, "set=%s sreg=%u dreg=%u\n",
+       ret = snprintf(buf, len, "set=%s sreg=%u dreg=%u",
                        l->set_name, l->sreg, l->dreg);
        SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
index 849cb4132089de914fc1db2f7dbbcba0bd95c172..39456768e5197f987fffd8dae271311871764eb9 100644 (file)
@@ -494,8 +494,6 @@ static int nft_rule_snprintf_default(char *buf, size_t size, struct nft_rule *r,
                ret = expr->ops->snprintf(buf+offset, len, type, flags, expr);
                SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
        }
-       ret = snprintf(buf+offset-1, len, "\n");
-       SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
        return ret;
 }
index 9454ace32874399b0d4039ff97b42d80a0cc2284..ef2d11d841a22120297f68aef8c75e59307939e0 100644 (file)
--- a/src/set.c
+++ b/src/set.c
@@ -270,10 +270,17 @@ int nft_set_snprintf(char *buf, size_t size, struct nft_set *s,
        int len = size, offset = 0;
        struct nft_set_elem *elem;
 
-       ret = snprintf(buf, size, "set=%s table=%s flags=%x\n",
+       ret = snprintf(buf, size, "set=%s table=%s flags=%x",
                        s->name, s->table, s->set_flags);
        SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
+       /* Empty set? Skip printinf of elements */
+       if (list_empty(&s->element_list))
+               return offset;
+
+       ret = snprintf(buf+offset, size, "\n");
+       SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
+
        list_for_each_entry(elem, &s->element_list, head) {
                ret = snprintf(buf+offset, size, "\t");
                SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
index 980faedfacc668e722a2cb7a1a62d5c75e43cce7..a2669ad7f79d9aaf2ac249c0097ef762d25c262c 100644 (file)
@@ -347,8 +347,6 @@ int nft_set_elem_snprintf(char *buf, size_t size, struct nft_set_elem *e,
                ret = snprintf(buf+offset, len, "%.8x ", e->data.val[i]);
                SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
        }
-       ret = snprintf(buf+offset, size, "\n");
-       SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
        return offset;
 }
index c963e6e9f01608021d4da28e2d25e8ecd4980ecf..2d72136b7ac9fae8e36dc2e7549dd6c0927c21df 100644 (file)
@@ -197,7 +197,7 @@ static int nft_table_snprintf_xml(char *buf, size_t size, struct nft_table *t)
 
 static int nft_table_snprintf_default(char *buf, size_t size, struct nft_table *t)
 {
-       return snprintf(buf, size, "table=%s family=%u flags=%x\n",
+       return snprintf(buf, size, "table=%s family=%u flags=%x",
                        t->name, t->family, t->table_flags);
 }