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@xxxxxxxxx> > --- > 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@xxxxxxxxxx > https://www.redhat.com/mailman/listinfo/libvir-list
Attachment:
signature.asc
Description: PGP signature
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list