From nobody Thu May 15 02:40:38 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 1514913161579284.3609947967659; Tue, 2 Jan 2018 09:12:41 -0800 (PST) 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 4AA11C065857; Tue, 2 Jan 2018 17:12:40 +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 245B25EDE4; Tue, 2 Jan 2018 17:12:40 +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 E0EBC3FA5B; Tue, 2 Jan 2018 17:12:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w02HCZX8003137 for ; Tue, 2 Jan 2018 12:12:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id D17515C888; Tue, 2 Jan 2018 17:12:35 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-45.brq.redhat.com [10.40.204.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id 41ACA17557 for ; Tue, 2 Jan 2018 17:12:35 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 2 Jan 2018 18:12:02 +0100 Message-Id: <837ee22a9b38d408913006d481cbf6a8f38a20bb.1514911024.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 09/18] util: Introduce virStringListMerge 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 02 Jan 2018 17:12:40 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" For two string lists merge one into the other one. Signed-off-by: Michal Privoznik --- src/libvirt_private.syms | 1 + src/util/virstring.c | 36 ++++++++++++++++++++++++++++++++++++ src/util/virstring.h | 3 +++ 3 files changed, 40 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d5c3b9abb..d807cdca6 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2764,6 +2764,7 @@ virStringListGetFirstWithPrefix; virStringListHasString; virStringListJoin; virStringListLength; +virStringListMerge; virStringListRemove; virStringMatch; virStringParsePort; diff --git a/src/util/virstring.c b/src/util/virstring.c index b2ebce27f..47d9efba2 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -239,6 +239,42 @@ virStringListRemove(char ***strings, } =20 =20 +/** + * virStringListMerge: + * @dst: a NULL-terminated array of strings to expand + * @src: a NULL-terminated array of strings + * + * Merges @src into @dst. Upon successful return from this + * function, @dst is resized to $(dst + src) elements and @src is + * freed. + * + * Returns 0 on success, -1 otherwise. + */ +int +virStringListMerge(char ***dst, + char ***src) +{ + size_t dst_len, src_len, i; + + if (!src || !*src) + return 0; + + dst_len =3D virStringListLength((const char **) *dst); + src_len =3D virStringListLength((const char **) *src); + + if (VIR_REALLOC_N(*dst, dst_len + src_len + 1) < 0) + return -1; + + for (i =3D 0; i <=3D src_len; i++) + (*dst)[i + dst_len] =3D (*src)[i]; + + /* Don't call virStringListFree() as it would free strings in + * @src. */ + VIR_FREE(*src); + return 0; +} + + /** * virStringListCopy: * @dst: where to store the copy of @strings diff --git a/src/util/virstring.h b/src/util/virstring.h index b19abaf9f..f42aaff62 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -46,6 +46,9 @@ char **virStringListAdd(const char **strings, void virStringListRemove(char ***strings, const char *item); =20 +int virStringListMerge(char ***dst, + char ***src); + int virStringListCopy(char ***dst, const char **src); =20 --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list