From nobody Mon Feb 9 13:08:17 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1612600509; cv=none; d=zohomail.com; s=zohoarc; b=Q6fOnovOZGqqQDRts3rwIZkUjiD6/fgy0xEvDx9O+F7IJMu6rQSHMn+/1rkZqyhR8CRud79qRH7kfFOonKYDAoQD6j3ZZcHkZ2Z/m2hqiY3/fAhGQyRA5+ljPtcVEOWKLHC17X1lGGljxjbsE1a5O/7C0OcaWeOhnZWTG8S7y1g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600509; 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=snaH0PaRyqano4XIcmyL0YLImDn4Ko0L+NEVaQ+QVCA=; b=nwuvgHJt8lzQl8/VGk1rYjqAiCIoClMZvnEWw+e41iBqo4VPNKLlWrAiW+iRrzf+KUwUXuSeATaLi80KThqNyngts0x0CDx88e1cLiTsQsqW+0B5PtlIZ2ha0R1xVHq7y8LiJZmK+z8oQmIIEduX4bmS5l3/iOJokm3sHt2Uua8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1612600509349293.31895642938025; Sat, 6 Feb 2021 00:35:09 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-484-wy0KVtrNOsyPxe32MmxndA-1; Sat, 06 Feb 2021 03:35:05 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5046C107AFD3; Sat, 6 Feb 2021 08:35:00 +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 274B41A873; Sat, 6 Feb 2021 08:35:00 +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 E2E0B18095CD; Sat, 6 Feb 2021 08:34:59 +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 1168Yw0p005597 for ; Sat, 6 Feb 2021 03:34:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id B215D60C7B; Sat, 6 Feb 2021 08:34:58 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id D1AB160C79 for ; Sat, 6 Feb 2021 08:34:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600508; 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=snaH0PaRyqano4XIcmyL0YLImDn4Ko0L+NEVaQ+QVCA=; b=AaiU4sTd0JHeU9K5tcIQA+dIvm7wt9Jgd4g1mnyYReZNq3uizdc7w+IimG/gJA4Q/Qf7nw IKQK4csokEduQAcp1huZOOUjtsw1+SSL9Uaorwy4rePeGngoBsAz6bTxPdbIqL5QWBX/u3 zYrZmJpzfdvyLfTllmchl40M409CZKE= X-MC-Unique: wy0KVtrNOsyPxe32MmxndA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 37/40] virStringSplitCount: Reimplement using g_strsplit and g_strv_length Date: Sat, 6 Feb 2021 09:32:59 +0100 Message-Id: <5d697ad1754a3674dcda7861a8c1166586ab1c85.1612599659.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 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.84 on 10.5.11.23 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa --- src/util/virstring.c | 72 +++----------------------------------------- src/util/virstring.h | 2 +- 2 files changed, 6 insertions(+), 68 deletions(-) diff --git a/src/util/virstring.c b/src/util/virstring.c index fa12b7dcd7..89d9ba4a13 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -43,28 +43,9 @@ VIR_LOG_INIT("util.string"); /** * virStringSplitCount: - * @string: a string to split - * @delim: a string which specifies the places at which to split - * the string. The delimiter is not included in any of the resulting - * strings, unless @max_tokens is reached. - * @max_tokens: the maximum number of pieces to split @string into. - * If this is 0, the string is split completely. - * @tokcount: If provided, the value is set to the count of pieces the str= ing - * was split to excluding the terminating NULL element. * - * Splits a string into a maximum of @max_tokens pieces, using the given - * @delim. If @max_tokens is reached, the remainder of @string is - * appended to the last token. - * - * As a special case, the result of splitting the empty string "" is an em= pty - * vector, not a vector containing a single string. The reason for this - * special case is that being able to represent an empty vector is typical= ly - * more useful than consistent handling of empty elements. If you do need - * to represent empty elements, you'll need to check for the empty string - * before calling virStringSplit(). - * - * Return value: a newly-allocated NULL-terminated array of strings. Use - * g_strfreev() to free it. + * A wrapper for g_strsplit which provides number of elements of the split + * string. */ char ** virStringSplitCount(const char *string, @@ -72,54 +53,11 @@ virStringSplitCount(const char *string, size_t max_tokens, size_t *tokcount) { - char **tokens =3D NULL; - size_t ntokens =3D 0; - size_t maxtokens =3D 0; - const char *remainder =3D string; - char *tmp; - size_t i; - - if (max_tokens =3D=3D 0) - max_tokens =3D INT_MAX; - - tmp =3D strstr(remainder, delim); - if (tmp) { - size_t delimlen =3D strlen(delim); - - while (--max_tokens && tmp) { - size_t len =3D tmp - remainder; - - if (VIR_RESIZE_N(tokens, maxtokens, ntokens, 1) < 0) - goto error; + GStrv ret =3D g_strsplit(string, delim, max_tokens); - tokens[ntokens] =3D g_strndup(remainder, len); - ntokens++; - remainder =3D tmp + delimlen; - tmp =3D strstr(remainder, delim); - } - } - if (*string) { - if (VIR_RESIZE_N(tokens, maxtokens, ntokens, 1) < 0) - goto error; - - tokens[ntokens] =3D g_strdup(remainder); - ntokens++; - } + *tokcount =3D g_strv_length(ret); - if (VIR_RESIZE_N(tokens, maxtokens, ntokens, 1) < 0) - goto error; - tokens[ntokens++] =3D NULL; - - if (tokcount) - *tokcount =3D ntokens - 1; - - return tokens; - - error: - for (i =3D 0; i < ntokens; i++) - VIR_FREE(tokens[i]); - VIR_FREE(tokens); - return NULL; + return ret; } diff --git a/src/util/virstring.h b/src/util/virstring.h index 18793a34b4..48b20f5c7d 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -26,7 +26,7 @@ char **virStringSplitCount(const char *string, const char *delim, size_t max_tokens, size_t *tokcount) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4); char *virStringListJoin(const char **strings, const char *delim) --=20 2.29.2