From nobody Mon Feb 9 08:55:27 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 155197349684428.036765820368373; Thu, 7 Mar 2019 07:44:56 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2CDDC300B915; Thu, 7 Mar 2019 15:44:55 +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 EEE3E60856; Thu, 7 Mar 2019 15:44:54 +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 73CDD3FA4C; Thu, 7 Mar 2019 15:44:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x27Fillp018669 for ; Thu, 7 Mar 2019 10:44:47 -0500 Received: by smtp.corp.redhat.com (Postfix) id A2D5B19C72; Thu, 7 Mar 2019 15:44:47 +0000 (UTC) Received: from kinshicho.brq.redhat.com (unknown [10.43.2.212]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2742A19C69 for ; Thu, 7 Mar 2019 15:44:46 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Thu, 7 Mar 2019 16:44:36 +0100 Message-Id: <20190307154437.1405-8-abologna@redhat.com> In-Reply-To: <20190307154437.1405-1-abologna@redhat.com> References: <20190307154437.1405-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 7/8] tests: Introduce testQemuCapsIterate() 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Thu, 07 Mar 2019 15:44:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This function iterates over a directory containing capabilities-related data, extract some useful bits of information from the file name, and calls a user-provided callback. Signed-off-by: Andrea Bolognani --- tests/testutilsqemu.c | 53 +++++++++++++++++++++++++++++++++++++++++++ tests/testutilsqemu.h | 8 +++++++ 2 files changed, 61 insertions(+) diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 61bf67d5ad..407cf91925 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -865,3 +865,56 @@ testQemuGetLatestCapsForArch(const char *dirname, virDirClose(&dir); return ret; } + + +int +testQemuCapsIterate(const char *dirname, + const char *suffix, + testQemuCapsIterateCallback callback, + void *opaque) +{ + struct dirent *ent; + DIR *dir =3D NULL; + int rc; + int ret =3D -1; + + if (!callback) + return 0; + + if (virDirOpen(&dir, dirname) < 0) + goto cleanup; + + while ((rc =3D virDirRead(dir, &ent, dirname) > 0)) { + char *tmp =3D ent->d_name; + char *base =3D NULL; + char *archName =3D NULL; + + /* Strip the trailing suffix, moving on if it's not present */ + if (!virStringStripSuffix(tmp, suffix)) + continue; + + /* Find the last dot, moving on if none is present */ + if (!(archName =3D strrchr(tmp, '.'))) + continue; + + /* The base name is everything before the last dot, and + * the architecture name everything after it */ + base =3D tmp; + archName[0] =3D '\0'; + archName++; + + /* Run the user-provided callback */ + if (callback(base, archName, opaque) < 0) + goto cleanup; + } + + if (rc < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + virDirClose(&dir); + + return ret; +} diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h index 5ae7f19473..183ce915f1 100644 --- a/tests/testutilsqemu.h +++ b/tests/testutilsqemu.h @@ -63,6 +63,14 @@ char *testQemuGetLatestCapsForArch(const char *dirname, const char *arch, const char *suffix); =20 +typedef int (*testQemuCapsIterateCallback)(const char *base, + const char *archName, + void *opaque); +int testQemuCapsIterate(const char *dirname, + const char *suffix, + testQemuCapsIterateCallback callback, + void *opaque); + # endif =20 #endif /* LIBVIRT_TESTUTILSQEMU_H */ --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list