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

Ilya Maximets i.maximets at ovn.org
Fri Oct 9 15:09:53 UTC 2020


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!

Applied to master.

Best regards, Ilya Maximets.


More information about the dev mailing list