diff options
author | Numan Siddique <nusiddiq@redhat.com> | 2020-09-18 20:45:36 +0530 |
---|---|---|
committer | Ilya Maximets <i.maximets@ovn.org> | 2020-10-08 16:34:57 +0200 |
commit | 7b2e999fd7594a9252d38a52cd40f131bb13d950 (patch) | |
tree | 73a09ff1646fe8d2c797c467c1574d9d63a909aa | |
parent | 61069e7be6df5784089e8a4e65f85b55a6166bb8 (diff) | |
download | openvswitch-7b2e999fd7594a9252d38a52cd40f131bb13d950.tar.gz |
smap: Add smap_get_uint() helper function.
This helper function is required by OVN.
Suggested-by: Dumitru Ceara <dceara@redhat.com>
Signed-off-by: Numan Siddique <nusiddiq@redhat.com>
Acked-by: Dumitru Ceara <dceara@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
-rw-r--r-- | lib/smap.c | 16 | ||||
-rw-r--r-- | lib/smap.h | 2 |
2 files changed, 18 insertions, 0 deletions
diff --git a/lib/smap.c b/lib/smap.c index 149b8b243..e82261497 100644 --- a/lib/smap.c +++ b/lib/smap.c @@ -248,6 +248,22 @@ smap_get_int(const struct smap *smap, const char *key, int def) } /* Gets the value associated with 'key' in 'smap' and converts it to an + * unsigned int. If 'key' is not in 'smap' or a valid unsigned integer + * can't be parsed from it's value, returns 'def'. */ +unsigned int +smap_get_uint(const struct smap *smap, const char *key, unsigned int def) +{ + const char *value = smap_get(smap, key); + unsigned int u_value; + + if (!value || !str_to_uint(value, 10, &u_value)) { + return def; + } + + return u_value; +} + +/* Gets the value associated with 'key' in 'smap' and converts it to an * unsigned long long. If 'key' is not in 'smap' or a valid number can't be * parsed from it's value, returns 'def'. */ unsigned long long int diff --git a/lib/smap.h b/lib/smap.h index 766c65f7f..a92115966 100644 --- a/lib/smap.h +++ b/lib/smap.h @@ -104,6 +104,8 @@ const char *smap_get_def(const struct smap *, const char *key, struct smap_node *smap_get_node(const struct smap *, const char *); bool smap_get_bool(const struct smap *smap, const char *key, bool def); int smap_get_int(const struct smap *smap, const char *key, int def); +unsigned int smap_get_uint(const struct smap *smap, const char *key, + unsigned int def); unsigned long long int smap_get_ullong(const struct smap *, const char *key, unsigned long long def); bool smap_get_uuid(const struct smap *, const char *key, struct uuid *); |