[libvirt] [PATCH v2 1/2] util: add virStringParseYesNo()
Peter Krempa
pkrempa at redhat.com
Tue Mar 12 10:33:47 UTC 2019
On Tue, Mar 12, 2019 at 18:56:22 +0900, Shotaro Gotanda wrote:
> This function parse the string "yes" into bool true and
> "no" into false, and return 0.
> If the string is anything other than "yes|no",
> this function return -1.
>
> Signed-off-by: Shotaro Gotanda <g.sho1500 at gmail.com>
> ---
> src/util/virstring.c | 23 +++++++++++++++++++++++
> src/util/virstring.h | 3 +++
> 2 files changed, 26 insertions(+)
>
> diff --git a/src/util/virstring.c b/src/util/virstring.c
> index 33f8191f45..945a8d0c84 100644
> --- a/src/util/virstring.c
> +++ b/src/util/virstring.c
> @@ -1548,3 +1548,26 @@ virStringParsePort(const char *str,
>
> return 0;
> }
> +
> +
> +/**
> + * virStringParseYesNo:
> + * @str: "yes|no" to parse, and the value must not be NULL.
> + * @port: pointer to parse and convert "yes|no" into
> + *
> + * Parses a string "yes|no" and convert it into true|false.
> + * Returns 0 on success and -1 on error.
> + */
> +int virStringParseYesNo(const char *str, bool *result)
> +{
> +
> + if (STREQ(str, "yes")) {
> + *result = true;
> + } else if (STREQ(str, "no")) {
> + *result = false;
> + } else {
> + return -1;
This does not conform to our coding style. Please make sure to read the
guidelines and run syntax-check before posting.
> + }
> +
> + return 0;
> +}
> diff --git a/src/util/virstring.h b/src/util/virstring.h
> index 1e36ac459c..9b01e8568a 100644
> --- a/src/util/virstring.h
> +++ b/src/util/virstring.h
> @@ -316,6 +316,9 @@ int virStringParsePort(const char *str,
> unsigned int *port)
> ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
>
> +int virStringParseYesNo(const char *str,
> + bool *result)
> + ATTRIBUTE_RETURN_CHECK;
> /**
> * VIR_AUTOSTRINGLIST:
> *
> --
> 2.19.1
>
> --
> libvir-list mailing list
> libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20190312/8b0fd03f/attachment-0001.sig>
More information about the libvir-list
mailing list