From nobody Mon Feb 9 17:35:39 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552458674160154.0918452346101; Tue, 12 Mar 2019 23:31:14 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6295930018C4; Wed, 13 Mar 2019 06:31:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3768E5D706; Wed, 13 Mar 2019 06:31:12 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E88EA3FB11; Wed, 13 Mar 2019 06:31:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2D6Ug6e029855 for ; Wed, 13 Mar 2019 02:30:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 865F917AD1; Wed, 13 Mar 2019 06:30:42 +0000 (UTC) Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 81B765DD84 for ; Wed, 13 Mar 2019 06:30:39 +0000 (UTC) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CF32E3ED89 for ; Wed, 13 Mar 2019 06:30:38 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id b2so787412pgl.9 for ; Tue, 12 Mar 2019 23:30:38 -0700 (PDT) Received: from localhost.localdomain ([157.82.204.204]) by smtp.googlemail.com with ESMTPSA id d26sm14573310pfn.86.2019.03.12.23.30.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 23:30:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mZ8u39s4i/BLSeFwdDn37Cxjt47/Mns9BQoUmkhpU90=; b=lLQxtd/3Fdag/vXwnjM3EKHSAuvzHTpzNCX+ALZKU7OMJYaAgBkNtx/eSqJtzAl2co SGMVKkvGJumq0s6Mg0qCy99BknaWPXmkHkbYf/24x4xaMUE/49M50Ps/5cFkLorpqAHG UGIhkcpeVyZ4iNcPlxrwL4FdsJiagsj6nxJgvQfXTpFDew998oDIWWSR1UN9Y8V1xryK k47TQluM/4LlMjc8KTlHqRyJfYkoI/8o40CQPYy0HTJY/hysLemahnpfwum7XIO6EhQK QZd8tyaA8wBwliiCGq4w7f02pV3w8J0yn+fu90W4VFLQzq4pv1To5GYiw5MDFmC+JehI GhYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mZ8u39s4i/BLSeFwdDn37Cxjt47/Mns9BQoUmkhpU90=; b=PLihaxl8OugV+AEMb4xNkGTrnTJtJn3D/9mcfXLT+gz4ZI+MlwvR9lO6qGhVmYG3SE 79yi0qoVTTGYzI6mcJOGoA2d6KSuKflPKCi2gZqvythTmPF9zDM9J9AX6n+qKAU/ltu4 ONtLIVDzbIf1oAcz3/5BMDJZQj/jk/6q/bmGCmVs/Wr5/ZJnG1nDYIocHeHGFUNcivOJ jj9wPdSGn71HSps6pNTN5OzLFAJV9hIk9BVdmZ6penyentQPGz3HTpIai+gi/Q0xLXYW QfAibZP7b1fx69Rx2kR+de4eBIF7GzcmdbJ53Od2nYSenAiw17mnBspLxUPmhbLgS151 d+iQ== X-Gm-Message-State: APjAAAXSl733dN7UdveZLOqIwjQ6A3TSOU/mfaTgqnQ8XoUf9/85s1s0 SuQZCp3zrmG1loDl3Kdtv5jrkLVRilWs+w== X-Google-Smtp-Source: APXvYqyY8WxpJXzZZvgpj+BSxAEeVHDVRMGbuWf1bjiYwpf8AGlsHy+LuBksiS/GylDLLRkN7GQPMQ== X-Received: by 2002:a17:902:9a43:: with SMTP id x3mr43343896plv.173.1552458637831; Tue, 12 Mar 2019 23:30:37 -0700 (PDT) From: Shotaro Gotanda To: libvir-list@redhat.com Date: Wed, 13 Mar 2019 15:30:10 +0900 Message-Id: <20190313063011.16317-2-g.sho1500@gmail.com> In-Reply-To: <20190313063011.16317-1-g.sho1500@gmail.com> References: <20190313063011.16317-1-g.sho1500@gmail.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 13 Mar 2019 06:30:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 13 Mar 2019 06:30:38 +0000 (UTC) for IP:'209.85.215.193' DOMAIN:'mail-pg1-f193.google.com' HELO:'mail-pg1-f193.google.com' FROM:'g.sho1500@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.142 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.215.193 mail-pg1-f193.google.com 209.85.215.193 mail-pg1-f193.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: Shotaro Gotanda Subject: [libvirt] [PATCH v3 1/2] util: add virStringParseYesNo() X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 13 Mar 2019 06:31:12 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Erik Skultety --- 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, =20 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 =3D true; + else if (STREQ(str, "no")) + *result =3D 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; =20 +int virStringParseYesNo(const char *str, + bool *result) + ATTRIBUTE_RETURN_CHECK; /** * VIR_AUTOSTRINGLIST: * --=20 2.19.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list