diff options
author | Phil Sutter <phil@nwl.cc> | 2020-12-19 02:24:16 +0100 |
---|---|---|
committer | Phil Sutter <phil@nwl.cc> | 2021-03-09 14:23:13 +0100 |
commit | d2824247a2bd62a81c7efd41b3a136488a8c6551 (patch) | |
tree | 52a42a70177e9534e2eeebceda9f25f0ecc98fc1 | |
parent | 54256a0401195e16f4c55eda849d28a264b55208 (diff) |
rule: Avoid printing trailing spaces
Introduce 'sep' variable to track whether something was printed already.
While being at it, introduce PRIu64 for 'handle' and 'position'
attributes.
Signed-off-by: Phil Sutter <phil@nwl.cc>
-rw-r--r-- | src/rule.c | 27 |
1 files changed, 18 insertions, 9 deletions
@@ -551,44 +551,53 @@ static int nftnl_rule_snprintf_default(char *buf, size_t size, { struct nftnl_expr *expr; int ret, remain = size, offset = 0, i; + const char *sep = ""; if (r->flags & (1 << NFTNL_RULE_FAMILY)) { - ret = snprintf(buf + offset, remain, "%s ", + ret = snprintf(buf + offset, remain, "%s%s", sep, nftnl_family2str(r->family)); SNPRINTF_BUFFER_SIZE(ret, remain, offset); + sep = " "; } if (r->flags & (1 << NFTNL_RULE_TABLE)) { - ret = snprintf(buf + offset, remain, "%s ", + ret = snprintf(buf + offset, remain, "%s%s", sep, r->table); SNPRINTF_BUFFER_SIZE(ret, remain, offset); + sep = " "; } if (r->flags & (1 << NFTNL_RULE_CHAIN)) { - ret = snprintf(buf + offset, remain, "%s ", + ret = snprintf(buf + offset, remain, "%s%s", sep, r->chain); SNPRINTF_BUFFER_SIZE(ret, remain, offset); + sep = " "; } if (r->flags & (1 << NFTNL_RULE_HANDLE)) { - ret = snprintf(buf + offset, remain, "%llu ", - (unsigned long long)r->handle); + ret = snprintf(buf + offset, remain, "%s%" PRIu64, sep, + r->handle); SNPRINTF_BUFFER_SIZE(ret, remain, offset); + sep = " "; } if (r->flags & (1 << NFTNL_RULE_POSITION)) { - ret = snprintf(buf + offset, remain, "%llu ", - (unsigned long long)r->position); + ret = snprintf(buf + offset, remain, "%s%" PRIu64, sep, + r->position); SNPRINTF_BUFFER_SIZE(ret, remain, offset); + sep = " "; } if (r->flags & (1 << NFTNL_RULE_ID)) { - ret = snprintf(buf + offset, remain, "%u ", r->id); + ret = snprintf(buf + offset, remain, "%s%u", sep, r->id); SNPRINTF_BUFFER_SIZE(ret, remain, offset); + sep = " "; } if (r->flags & (1 << NFTNL_RULE_POSITION_ID)) { - ret = snprintf(buf + offset, remain, "%u ", r->position_id); + ret = snprintf(buf + offset, remain, "%s%u", sep, + r->position_id); SNPRINTF_BUFFER_SIZE(ret, remain, offset); + sep = " "; } ret = snprintf(buf + offset, remain, "\n"); |