diff options
author | Phil Sutter <phil@nwl.cc> | 2023-11-22 20:41:34 +0100 |
---|---|---|
committer | Phil Sutter <phil@nwl.cc> | 2023-11-23 18:01:21 +0100 |
commit | 1af6984c57cce5169491d308b58a9c85464b2159 (patch) | |
tree | 36919e665a167fdabac469d7912d1dfde2e3b7bd /libxtables | |
parent | b1c5270bdf35138d7459349df487e1c9e18c4c32 (diff) |
libxtables: Introduce xtables_strtoul_base()
Semantically identical to xtables_strtoul() but accepts the base as
parameter so callers may force it irrespective of number prefix. The old
xtables_strtoul() becomes a shallow wrapper.
Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'libxtables')
-rw-r--r-- | libxtables/xtables.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/libxtables/xtables.c b/libxtables/xtables.c index ba9ceaeb..b4339e8d 100644 --- a/libxtables/xtables.c +++ b/libxtables/xtables.c @@ -580,23 +580,23 @@ int xtables_load_ko(const char *modprobe, bool quiet) } /** - * xtables_strtou{i,l} - string to number conversion + * xtables_strtoul_base - string to number conversion * @s: input string * @end: like strtoul's "end" pointer * @value: pointer for result * @min: minimum accepted value * @max: maximum accepted value + * @base: assumed base of value * * If @end is NULL, we assume the caller wants a "strict strtoul", and hence * "15a" is rejected. * In either case, the value obtained is compared for min-max compliance. - * Base is always 0, i.e. autodetect depending on @s. * * Returns true/false whether number was accepted. On failure, *value has * undefined contents. */ -bool xtables_strtoul(const char *s, char **end, uintmax_t *value, - uintmax_t min, uintmax_t max) +bool xtables_strtoul_base(const char *s, char **end, uintmax_t *value, + uintmax_t min, uintmax_t max, unsigned int base) { uintmax_t v; const char *p; @@ -608,7 +608,7 @@ bool xtables_strtoul(const char *s, char **end, uintmax_t *value, ; if (*p == '-') return false; - v = strtoumax(s, &my_end, 0); + v = strtoumax(s, &my_end, base); if (my_end == s) return false; if (end != NULL) @@ -625,6 +625,12 @@ bool xtables_strtoul(const char *s, char **end, uintmax_t *value, return false; } +bool xtables_strtoul(const char *s, char **end, uintmax_t *value, + uintmax_t min, uintmax_t max) +{ + return xtables_strtoul_base(s, end, value, min, max, 0); +} + bool xtables_strtoui(const char *s, char **end, unsigned int *value, unsigned int min, unsigned int max) { |