On 9/18/20 5:15 PM, [email protected] wrote: > From: Numan Siddique <[email protected]> > > This helper function is required by OVN. > > Suggested-by: Dumitru Ceara <[email protected]> > Signed-off-by: Numan Siddique <[email protected]> > --- > lib/smap.c | 16 ++++++++++++++++ > lib/smap.h | 2 ++ > 2 files changed, 18 insertions(+) > > diff --git a/lib/smap.c b/lib/smap.c > index 149b8b243..e82261497 100644 > --- a/lib/smap.c > +++ b/lib/smap.c > @@ -247,6 +247,22 @@ smap_get_int(const struct smap *smap, const char *key, > int def) > return i_value; > } > > +/* 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'. */ > 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 *); >
Looks good to me. Acked-by: Dumitru Ceara <[email protected]> Thanks, Dumitru _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
