From nobody Mon Feb 9 11:08:16 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1637845166; cv=none; d=zohomail.com; s=zohoarc; b=b4S81r1CWJPy8DIX4N4rEDNW19lGllS76pwLFjlQg0atMLNxJ9lCUIGMqQ9svaa6dLI3slU8OOwYD0ez4TAjx172P/X3laAT1/0lTaowUZqXiR+XA6R86ivjEqyZZQN69hQ3WVWsIcUdj+y/n2CeRoPFzLRwHyLMKfSuaPaEkVI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637845166; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3sP6hE1TWlC+7PKBTnDCUQEutZkRjM4L9JDFEHSVOCo=; b=Nedu94y+FtTF7dCIgXG6UpRaaxC/wgjqH54oXWeB4h9NFtRvKABdESHE+w3ZxHQRk9KEixabrJNzQngeOoMes4v1RNKxuC2cwxZpdezaysDxAbF2HSvg5D//i4KXXvzm3gsDkXOAjg+uEbi72MXF4ImLtyxElI8wfBYIEufKU4I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1637845166481453.5968842718721; Thu, 25 Nov 2021 04:59:26 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-506-Wpu0u3RJP3CWirl9sLSEoA-1; Thu, 25 Nov 2021 07:59:23 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1D69F1023F4E; Thu, 25 Nov 2021 12:59:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EEAE65D740; Thu, 25 Nov 2021 12:59:18 +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 74CCE1809C8A; Thu, 25 Nov 2021 12:59:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1APCxEus030979 for ; Thu, 25 Nov 2021 07:59:14 -0500 Received: by smtp.corp.redhat.com (Postfix) id 98A4C5F4EF; Thu, 25 Nov 2021 12:59:14 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 05FD05D740 for ; Thu, 25 Nov 2021 12:59:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637845165; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=3sP6hE1TWlC+7PKBTnDCUQEutZkRjM4L9JDFEHSVOCo=; b=Kl6opXyBLBAYJQhPeR0XuyZmOH7NeIxEnvBTARYY27j+RlXlUCdFtVpcx6qlOqgP0o/cHq AolnJDQ8lnvixG6xw3orxjS94KQJa2fmStB76P2kbmdEp8TElvbtdskQecSCZE9lP0nzRV 3//aMFiuUiraCKVY2CPvtwCGDjuRctA= X-MC-Unique: Wpu0u3RJP3CWirl9sLSEoA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/6] util: enum: Add helpers for converting virTristate* to a plain bool Date: Thu, 25 Nov 2021 13:59:06 +0100 Message-Id: <3184b5e4aab3b02a827f1972447208af022f131c.1637845012.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1637845166991100003 Content-Type: text/plain; charset="utf-8" The helpers will update the passed boolean if the tristate's value is not _ABSENT. Signed-off-by: Peter Krempa --- src/libvirt_private.syms | 2 ++ src/util/virenum.c | 54 ++++++++++++++++++++++++++++++++++++++++ src/util/virenum.h | 2 ++ 3 files changed, 58 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b98cb0f66d..49795e5b81 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2147,9 +2147,11 @@ ebtablesRemoveForwardAllowIn; virEnumFromString; virEnumToString; virTristateBoolFromBool; +virTristateBoolToBool; virTristateBoolTypeFromString; virTristateBoolTypeToString; virTristateSwitchFromBool; +virTristateSwitchToBool; virTristateSwitchTypeFromString; virTristateSwitchTypeToString; diff --git a/src/util/virenum.c b/src/util/virenum.c index 26093bd795..103f00b524 100644 --- a/src/util/virenum.c +++ b/src/util/virenum.c @@ -47,6 +47,33 @@ virTristateBoolFromBool(bool val) } +/** + * virTristateBoolToBool: + * @t: a virTristateBool value + * @b: pointer to a boolean to be updated according to the value of @t + * + * The value pointed to by @b is updated if the tristate value @t is not a= bsent. + */ +void +virTristateBoolToBool(virTristateBool t, + bool *b) +{ + switch (t) { + case VIR_TRISTATE_BOOL_YES: + *b =3D true; + break; + + case VIR_TRISTATE_BOOL_NO: + *b =3D false; + break; + + case VIR_TRISTATE_BOOL_ABSENT: + case VIR_TRISTATE_BOOL_LAST: + break; + } +} + + virTristateSwitch virTristateSwitchFromBool(bool val) { @@ -57,6 +84,33 @@ virTristateSwitchFromBool(bool val) } +/** + * virTristateSwitchToBool: + * @t: a virTristateSwitch value + * @b: pointer to a boolean to be updated according to the value of @t + * + * The value pointed to by @b is updated if the tristate value @t is not a= bsent. + */ +void +virTristateSwitchToBool(virTristateSwitch t, + bool *b) +{ + switch (t) { + case VIR_TRISTATE_SWITCH_ON: + *b =3D true; + break; + + case VIR_TRISTATE_SWITCH_OFF: + *b =3D false; + break; + + case VIR_TRISTATE_SWITCH_ABSENT: + case VIR_TRISTATE_SWITCH_LAST: + break; + } +} + + int virEnumFromString(const char * const *types, unsigned int ntypes, diff --git a/src/util/virenum.h b/src/util/virenum.h index d74af35530..98f01d574d 100644 --- a/src/util/virenum.h +++ b/src/util/virenum.h @@ -68,7 +68,9 @@ VIR_ENUM_DECL(virTristateBool); VIR_ENUM_DECL(virTristateSwitch); virTristateBool virTristateBoolFromBool(bool val); +void virTristateBoolToBool(virTristateBool t, bool *b); virTristateSwitch virTristateSwitchFromBool(bool val); +void virTristateSwitchToBool(virTristateSwitch t, bool *b); /* the two enums must be in sync to be able to use helpers interchangeably= in * some special cases */ --=20 2.31.1