From nobody Thu May 15 13:49:29 2025 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1507206771059746.147625398374; Thu, 5 Oct 2017 05:32:51 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BA7B8C059B7C; Thu, 5 Oct 2017 12:32:49 +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 5880561983; Thu, 5 Oct 2017 12:32:49 +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 72F033FAD0; Thu, 5 Oct 2017 12:32:48 +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 v95C6XAn024794 for ; Thu, 5 Oct 2017 08:06:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id CDCB85D961; Thu, 5 Oct 2017 12:06:33 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D71C5D9C0; Thu, 5 Oct 2017 12:06:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BA7B8C059B7C Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 5 Oct 2017 14:06:17 +0200 Message-Id: <3d07f9979579122b89cfc25241a0dd87943c9e0f.1507205097.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH v2 1/4] util: Add functions to simplify bool->virTristate(Bool|Switch) assignment 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: , MIME-Version: 1.0 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 05 Oct 2017 12:32:50 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" virTristateBoolFromBool and virTristateSwitchFromBool convert a boolean to the correct enum value. --- src/libvirt_private.syms | 2 ++ src/util/virutil.c | 20 ++++++++++++++++++++ src/util/virutil.h | 3 +++ 3 files changed, 25 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 7a12d6a14..9243c5591 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2950,8 +2950,10 @@ virSetNonBlock; virSetSockReuseAddr; virSetUIDGID; virSetUIDGIDWithCaps; +virTristateBoolFromBool; virTristateBoolTypeFromString; virTristateBoolTypeToString; +virTristateSwitchFromBool; virTristateSwitchTypeFromString; virTristateSwitchTypeToString; virUpdateSelfLastChanged; diff --git a/src/util/virutil.c b/src/util/virutil.c index e08f9fa4a..170e92192 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -100,6 +100,26 @@ VIR_ENUM_IMPL(virTristateSwitch, VIR_TRISTATE_SWITCH_L= AST, "off") +virTristateBool +virTristateBoolFromBool(bool val) +{ + if (val) + return VIR_TRISTATE_BOOL_YES; + else + return VIR_TRISTATE_BOOL_NO; +} + + +virTristateSwitch +virTristateSwitchFromBool(bool val) +{ + if (val) + return VIR_TRISTATE_SWITCH_ON; + else + return VIR_TRISTATE_SWITCH_OFF; +} + + #ifndef WIN32 int virSetInherit(int fd, bool inherit) diff --git a/src/util/virutil.h b/src/util/virutil.h index 49382557f..a862a8a63 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -193,6 +193,9 @@ typedef enum { VIR_ENUM_DECL(virTristateBool) VIR_ENUM_DECL(virTristateSwitch) +virTristateBool virTristateBoolFromBool(bool val); +virTristateSwitch virTristateSwitchFromBool(bool val); + /* the two enums must be in sync to be able to use helpers interchangeably= in * some special cases */ verify((int)VIR_TRISTATE_BOOL_YES =3D=3D (int)VIR_TRISTATE_SWITCH_ON); --=20 2.14.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list