From nobody Mon Feb 9 07:38:21 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1593772354; cv=none; d=zohomail.com; s=zohoarc; b=VBBjhOT81rS5jrSEoULpVmH1en1DOBoMYKrwbSzwX4GV9+pMJECZsP0v/akptUmKvDg9pO6vSQxNh1hW+bV7dwBwekcgCHT456g5Vm2J2kInVdmuxGunTVm+yMBGwHDy24S6mE+RgiXeK5CjjfMbIntRjiZiLYP0/wUAhsfMdts= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593772354; 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=s9Snrs4t53DN8m45mB921Odf+rYuenmY3l3hlmKm1H8=; b=AuJ3MtNjKuBRkp6ZEBlVKMmF7Wia3xC2W+UThCmN77oPrAG4kpNdWizjATlpDvoCr1ZvE0EfR26aa6loPPNiTTUqdu19ZokJLKhDu8pIUSUAOYXOvwrql+/kv0MCmw9j6nPrbgLnPVW3oFPd+s9DyhqIKLkYpFKAfiESLhJoB4Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1593772354636349.80698210107323; Fri, 3 Jul 2020 03:32:34 -0700 (PDT) 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-342--Qq-vMHONjW49rBNsuyljg-1; Fri, 03 Jul 2020 06:32:31 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2D28318A8225; Fri, 3 Jul 2020 10:32:26 +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 0A2B31053B05; Fri, 3 Jul 2020 10:32:26 +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 BA8DD1809561; Fri, 3 Jul 2020 10:32:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 063AT3Qf016969 for ; Fri, 3 Jul 2020 06:29:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6C9887BD43; Fri, 3 Jul 2020 10:29:03 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id E01B679242 for ; Fri, 3 Jul 2020 10:29:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593772353; 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=s9Snrs4t53DN8m45mB921Odf+rYuenmY3l3hlmKm1H8=; b=Caw1S3rKPtVtHc74fyUp0qdMzZllZeSra1CpzvKXtQzDbC8Q5XNK2pGSbjHBw8wUwfwX9X jow0GMdRIDr6kuAWdtt345WyqZuei09grNSRo58e+I66TQsDWshN8QONYK7kaUvB0Cv5By XjXw9U5o17K67WMYrWOUi/dZZuhreQM= X-MC-Unique: -Qq-vMHONjW49rBNsuyljg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/9] virstring: Introduce virStringIsNull() Date: Fri, 3 Jul 2020 12:28:43 +0200 Message-Id: <072101003d55f0f76d84f5717ae425f6a825da3b.1593771693.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.22 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" This function will be used to detect zero buffers (which are going to be interpreted as hole in virStream later). I shamelessly took inspiration from coreutils. Signed-off-by: Michal Privoznik --- src/libvirt_private.syms | 1 + src/util/virstring.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/util/virstring.h | 2 ++ 3 files changed, 43 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ae0e253ab9..1d80aeb833 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3197,6 +3197,7 @@ virStringHasChars; virStringHasControlChars; virStringHasSuffix; virStringIsEmpty; +virStringIsNull; virStringIsPrintable; virStringListAdd; virStringListAutoFree; diff --git a/src/util/virstring.c b/src/util/virstring.c index e9e792f3bf..7f6871d5ab 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -1404,3 +1404,43 @@ int virStringParseYesNo(const char *str, bool *resul= t) =20 return 0; } + + +/** + * virStringIsNull: + * @buf: buffer to check + * @len: the length of the buffer + * + * For given buffer @buf and its size @len determine whether + * it contains only zero bytes or not. + * + * Returns: true if buffer is full of zero bytes, + * false otherwise. + */ +bool virStringIsNull(const char *buf, size_t len) +{ + const char *p =3D buf; + + if (!len) + return true; + + /* Check up to 16 first bytes. memcmp() below uses block of sizeof(lon= g) + * size (in most cases on 64bits is 8 bytes), doing twice the size jus= t to + * be safe. */ + for (;;) { + if (*p) + return false; + + p++; + len--; + + if (!len) + return true; + + if ((len & (2 * sizeof(long))) =3D=3D 0) + break; + } + + /* Now we know first 16 bytes are NUL, memcmp with self. */ + return memcmp(buf, p, len) =3D=3D 0; +} diff --git a/src/util/virstring.h b/src/util/virstring.h index 360c68395c..d0e54358ac 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -185,6 +185,8 @@ int virStringParsePort(const char *str, int virStringParseYesNo(const char *str, bool *result) G_GNUC_WARN_UNUSED_RESULT; +bool virStringIsNull(const char *buf, size_t len); + /** * VIR_AUTOSTRINGLIST: * --=20 2.26.2