Re: [PATCH v3 1/2] util: add virStringParseYesNo()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Mar 13, 2019 at 03:30:10PM +0900, Shotaro Gotanda wrote:
> This function parse the string "yes" into bool true and
> "no" into false, and returns 0.
> If the string is anything other than "yes|no",
> this function returns -1.
>
> Signed-off-by: Shotaro Gotanda <g.sho1500@xxxxxxxxx>
> ---
>  src/util/virstring.c | 21 +++++++++++++++++++++
>  src/util/virstring.h |  3 +++
>  2 files changed, 24 insertions(+)
>
> diff --git a/src/util/virstring.c b/src/util/virstring.c
> index 33f8191f45..3bbe36ea25 100644
> --- a/src/util/virstring.c
> +++ b/src/util/virstring.c
> @@ -1548,3 +1548,24 @@ 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

^This one looks like a copy-paste from virStringParsePort ;)

> + *
> + * Parses a string "yes|no" and convert it into true|false.

...converts it into a boolean.

> + * 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;
> +
> +    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)

^misaligned

The function should also be added to src/libvirt_private.syms

I tweaked the commit message a tiny bit and I'll perform the adjustments I
noted before pushing by squashing the following:

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 960a97cf1d..92a86943b1 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2988,6 +2988,7 @@ virStringListRemove;
 virStringMatch;
 virStringMatchesNameSuffix;
 virStringParsePort;
+virStringParseYesNo;
 virStringReplace;
 virStringSearch;
 virStringSortCompare;
diff --git a/src/util/virstring.c b/src/util/virstring.c
index d9d6c0a33e..95bd7d225e 100644
--- a/src/util/virstring.c
+++ b/src/util/virstring.c
@@ -1552,10 +1552,11 @@ virStringParsePort(const char *str,

 /**
  * virStringParseYesNo:
- * @str: "yes|no" to parse, and the value must not be NULL.
- * @port: pointer to parse and convert "yes|no" into
+ * @str: "yes|no" to parse, must not be NULL.
+ * @result: pointer to the boolean result of @str conversion
+ *
+ * Parses a "yes|no" string and converts it into a boolean.
  *
- * 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)
diff --git a/src/util/virstring.h b/src/util/virstring.h
index 9b01e8568a..b0fedf96a3 100644
--- a/src/util/virstring.h
+++ b/src/util/virstring.h
@@ -317,7 +317,7 @@ int virStringParsePort(const char *str,
     ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;

 int virStringParseYesNo(const char *str,
-                       bool *result)
+                        bool *result)
     ATTRIBUTE_RETURN_CHECK;
 /**

Reviewed-by: Erik Skultety <eskultet@xxxxxxxxxx>

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux