From nobody Sun Feb 8 17:13:24 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1568913247; cv=none; d=zoho.com; s=zohoarc; b=EdzjXoeBBwlpR6F8kPzxTVJY3HhXgLAY/ZjnXjchawATb3AWAgwBPzIKQkTPMKNpXgwcFJJnOMQ6kiWPLdEO8LpOh9kVzh/SG9mtfMoEwIdD0cqtDhq9Vvocgqq4wH9piuzOOKxLDLJtLD8TJqOeaKuIRBiRCp6h9I7eh/3bLCk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568913247; 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:ARC-Authentication-Results; bh=X4j5fx3OddD3SkpHSK1hhvKcd3neEgv5i53ju9PbhR0=; b=jgJui+RXxp1MPCYYS++EtTIaJ6GxtILtRC9+KNbB5eF35oOPNd8Mp5DPlo6YLUkBGs1CbhsHEfsNCeB83NvdItYeSdPxuqQcbOd/2gAdVYGfKg+ghdxzd9S7Dw3tl3Wiyf0laFd+Ra6FbDr6aFnSX9T3RkSU1qMkVh3YGf5kstg= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568913247312200.48332151842897; Thu, 19 Sep 2019 10:14:07 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6FECE44FB1; Thu, 19 Sep 2019 17:14:05 +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 489DB404D; Thu, 19 Sep 2019 17:14:05 +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 0299B180BA9F; Thu, 19 Sep 2019 17:14:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8JHDcil004632 for ; Thu, 19 Sep 2019 13:13:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8107960BF1; Thu, 19 Sep 2019 17:13:38 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 080B060C5E for ; Thu, 19 Sep 2019 17:13:35 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 19 Sep 2019 19:13:09 +0200 Message-Id: <119fdbec5f2d3ee4a9c6a5d8d5f55d73773c2d25.1568911535.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 06/22] util: typedparam: Separate code to assign value to typed parameter 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 19 Sep 2019 17:14:05 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The code will be reused in other function. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virtypedparam.c | 55 ++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c index d9f8203796..9f86166707 100644 --- a/src/util/virtypedparam.c +++ b/src/util/virtypedparam.c @@ -205,24 +205,12 @@ virTypedParameterToString(virTypedParameterPtr param) return value; } -/* Assign name, type, and the appropriately typed arg to param; in the - * case of a string, the caller is assumed to have malloc'd a string, - * or can pass NULL to have this function malloc an empty string. - * Return 0 on success, -1 after an error message on failure. */ -int -virTypedParameterAssign(virTypedParameterPtr param, const char *name, - int type, ...) -{ - va_list ap; - int ret =3D -1; - - va_start(ap, type); - if (virStrcpyStatic(param->field, name) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, _("Field name '%s' too long= "), - name); - goto cleanup; - } +static int +virTypedParameterAssignValueAP(virTypedParameterPtr param, + int type, + va_list ap) +{ param->type =3D type; switch (type) { case VIR_TYPED_PARAM_INT: @@ -246,17 +234,40 @@ virTypedParameterAssign(virTypedParameterPtr param, c= onst char *name, case VIR_TYPED_PARAM_STRING: param->value.s =3D va_arg(ap, char *); if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) - goto cleanup; + return -1; break; default: virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected type %d for field %s"), type, name); - goto cleanup; + _("unexpected type %d for field %s"), type, + NULLSTR(param->field)); + return -1; } - ret =3D 0; - cleanup: + return 0; +} + + +/* Assign name, type, and the appropriately typed arg to param; in the + * case of a string, the caller is assumed to have malloc'd a string, + * or can pass NULL to have this function malloc an empty string. + * Return 0 on success, -1 after an error message on failure. */ +int +virTypedParameterAssign(virTypedParameterPtr param, const char *name, + int type, ...) +{ + va_list ap; + int ret =3D -1; + + if (virStrcpyStatic(param->field, name) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, _("Field name '%s' too long= "), + name); + return -1; + } + + va_start(ap, type); + ret =3D virTypedParameterAssignValueAP(param, type, ap); va_end(ap); + return ret; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list