[ovs-dev] [PATCH] smap: Add smap_get_uint() helper function.

Numan Siddique numans at ovn.org
Mon Oct 12 18:03:23 UTC 2020


On Fri, Oct 9, 2020 at 8:40 PM Ilya Maximets <i.maximets at ovn.org> wrote:
>
> On 9/18/20 5:27 PM, Dumitru Ceara wrote:
> > On 9/18/20 5:15 PM, numans at ovn.org wrote:
> >> From: Numan Siddique <nusiddiq at redhat.com>
> >>
> >> This helper function is required by OVN.
> >>
> >> Suggested-by: Dumitru Ceara <dceara at redhat.com>
> >> Signed-off-by: Numan Siddique <nusiddiq at redhat.com>
> >> ---
> >>  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 <dceara at redhat.com>
>
> Thanks, Numan and Dumitru!

Thanks Ilya and Dumitru.

Numan

>
> Applied to master.
>
> Best regards, Ilya Maximets.
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>


More information about the dev mailing list