[RFCv2 05/46] util: Add helper functions for 'bool' and 'time_t' and cooperate with xmlgen
Shi Lei
shi_lei at massclouds.com
Mon Dec 7 04:01:02 UTC 2020
On 2020-12-05 at 02:02, DanielP. Berrangé wrote:
>On Fri, Sep 04, 2020 at 11:34:57AM +0800, Shi Lei wrote:
>> Signed-off-by: Shi Lei <shi_lei at massclouds.com>
>> ---
>> src/libvirt_private.syms | 3 +++
>> src/util/virstring.c | 57 ++++++++++++++++++++++++++++++++++++++++
>> src/util/virstring.h | 9 +++++++
>> 3 files changed, 69 insertions(+)
>>
>> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
>> index 191eab0..4ad9d1e 100644
>> --- a/src/libvirt_private.syms
>> +++ b/src/libvirt_private.syms
>> @@ -3242,6 +3242,7 @@ virStringStripSuffix;
>> virStringToUpper;
>> virStringTrimOptionalNewline;
>> virStrncpy;
>> +virStrToBool;
>> virStrToDouble;
>> virStrToLong_i;
>> virStrToLong_l;
>> @@ -3252,6 +3253,8 @@ virStrToLong_ul;
>> virStrToLong_ull;
>> virStrToLong_ullp;
>> virStrToLong_ulp;
>> +virStrToTime;
>> +virTimeFormatBuf;
>> virTrimSpaces;
>>
>>
>> diff --git a/src/util/virstring.c b/src/util/virstring.c
>> index de2ef96..23ade40 100644
>> --- a/src/util/virstring.c
>> +++ b/src/util/virstring.c
>> @@ -1349,3 +1349,60 @@ int virStringParseYesNo(const char *str, bool *result)
>>
>> return 0;
>> }
>> +
>> +
>> +int
>> +virStrToBool(const char *str, const char *truevalue, bool *result)
>> +{
>> + if (STREQ(str, truevalue))
>> + *result = true;
>> + else
>> + *result = false;
>> +
>> + return 0;
>> +}
>
>I'd suggest we should explicitly check both the true and false
>values, and raise an error for any other value.
>
>I think we probably ought to have wrappers for the pairs of words
>we consider sane. eg virStrToBoolYesNo, virStrToBoolTrueFalse
>and virStrToBoolOnOff I think are probably the only ones we want
>to permit
Okay.
Shi Lei
>
>> +
>> +
>
>Regards,
>Daniel
>--
>|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
>|: https://libvirt.org -o- https://fstop138.berrange.com :|
>|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
>
More information about the libvir-list
mailing list