diff options
author | Phil Sutter <phil@nwl.cc> | 2021-03-09 13:41:44 +0100 |
---|---|---|
committer | Phil Sutter <phil@nwl.cc> | 2021-03-15 12:23:23 +0100 |
commit | a00d9d06b5021c27333e52e88b99493fa56d15a1 (patch) | |
tree | a6fb17354e6669cdaefd12fa78d4c3592f944b63 /src/ruleset.c | |
parent | 960c8e6174374ee113b290c304365bf02ed346d6 (diff) |
Get rid of single option switch statements
Replace each by a conditional testing the only valid case.
There is one odd example, namely src/set.c: When printing a set with
type NFTNL_OUTPUT_XML, the relevant function would return 0 instead of
-1 like all others. Just drop it assuming nothing depends on that
(faulty) behaviour.
Cc: Arturo Borrero <arturo.borrero.glez@gmail.com>
Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'src/ruleset.c')
-rw-r--r-- | src/ruleset.c | 26 |
1 files changed, 3 insertions, 23 deletions
diff --git a/src/ruleset.c b/src/ruleset.c index f904aa4..4788cc0 100644 --- a/src/ruleset.c +++ b/src/ruleset.c @@ -522,21 +522,6 @@ nftnl_ruleset_do_snprintf(char *buf, size_t remain, return offset; } -static int nftnl_ruleset_cmd_snprintf(char *buf, size_t size, - const struct nftnl_ruleset *r, uint32_t cmd, - uint32_t type, uint32_t flags) -{ - switch (type) { - case NFTNL_OUTPUT_DEFAULT: - case NFTNL_OUTPUT_JSON: - return nftnl_ruleset_do_snprintf(buf, size, r, cmd, type, flags); - case NFTNL_OUTPUT_XML: - default: - errno = EOPNOTSUPP; - return -1; - } -} - EXPORT_SYMBOL(nftnl_ruleset_snprintf); int nftnl_ruleset_snprintf(char *buf, size_t size, const struct nftnl_ruleset *r, uint32_t type, uint32_t flags) @@ -544,17 +529,12 @@ int nftnl_ruleset_snprintf(char *buf, size_t size, const struct nftnl_ruleset *r if (size) buf[0] = '\0'; - switch (type) { - case NFTNL_OUTPUT_DEFAULT: - case NFTNL_OUTPUT_JSON: - return nftnl_ruleset_cmd_snprintf(buf, size, r, - nftnl_flag2cmd(flags), type, - flags); - case NFTNL_OUTPUT_XML: - default: + if (type != NFTNL_OUTPUT_DEFAULT) { errno = EOPNOTSUPP; return -1; } + return nftnl_ruleset_do_snprintf(buf, size, r, nftnl_flag2cmd(flags), + type, flags); } static int nftnl_ruleset_fprintf_tables(FILE *fp, const struct nftnl_ruleset *rs, |