Message ID | 20200918151536.1474050-1-numans@ovn.org |
---|---|
State | Accepted |
Commit | 7b2e999fd7594a9252d38a52cd40f131bb13d950 |
Headers | show |
Series | [ovs-dev] smap: Add smap_get_uint() helper function. | expand |
On 9/18/20 5:15 PM, numans@ovn.org wrote: > From: Numan Siddique <nusiddiq@redhat.com> > > This helper function is required by OVN. > > Suggested-by: Dumitru Ceara <dceara@redhat.com> > Signed-off-by: Numan Siddique <nusiddiq@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@redhat.com> Thanks, Dumitru
On 9/18/20 5:27 PM, Dumitru Ceara wrote: > On 9/18/20 5:15 PM, numans@ovn.org wrote: >> From: Numan Siddique <nusiddiq@redhat.com> >> >> This helper function is required by OVN. >> >> Suggested-by: Dumitru Ceara <dceara@redhat.com> >> Signed-off-by: Numan Siddique <nusiddiq@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@redhat.com> Thanks, Numan and Dumitru! Applied to master. Best regards, Ilya Maximets.
On Fri, Oct 9, 2020 at 8:40 PM Ilya Maximets <i.maximets@ovn.org> wrote: > > On 9/18/20 5:27 PM, Dumitru Ceara wrote: > > On 9/18/20 5:15 PM, numans@ovn.org wrote: > >> From: Numan Siddique <nusiddiq@redhat.com> > >> > >> This helper function is required by OVN. > >> > >> Suggested-by: Dumitru Ceara <dceara@redhat.com> > >> Signed-off-by: Numan Siddique <nusiddiq@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@redhat.com> > > Thanks, Numan and Dumitru! Thanks Ilya and Dumitru. Numan > > Applied to master. > > Best regards, Ilya Maximets. > _______________________________________________ > dev mailing list > dev@openvswitch.org > https://mail.openvswitch.org/mailman/listinfo/ovs-dev >
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 *);