From nobody Mon Feb 9 07:23:52 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) client-ip=216.205.24.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1585120405; cv=none; d=zohomail.com; s=zohoarc; b=Sqt4VUOSQUm7zJNcY64wmVJhiCH8YYLHEcPOXCmVnOV4B8c2RtNtx1ycglS7XP+ggK/mfr/ePTj08lqf4cFWqS9ecDFDjwgNVtlE+IcrHYBNkzFVdgUMFdRrJzSckziIf0s9+/sqsZuFPPyoQfVZBhf2JQSzGcAX/DVLJ89wzJo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585120405; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=uuI/9Av/7+3r/ZEsVbreeEvSEk1jWUB4R1XKgd1ZKtY=; b=ddn8EMm6cdIH/E0n7E6H32rdKJLsncde1F3wF2JvvcjpjrUzBUfYQJXZD+Cuxht3NBZAEaPuVmc51jHeg9Vk5ftPbwMdHtawQB+I93iO+wo1amVxrmWDQ1ASzYN2qpWGV4O5zkXGQ5Kfg4j+9+vgbJu04/33cq840rmOLWQ1DCg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [216.205.24.74]) by mx.zohomail.com with SMTPS id 1585120405821804.0636595304544; Wed, 25 Mar 2020 00:13:25 -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-243-fohCpBtpOc-o-TMyXpNv5w-1; Wed, 25 Mar 2020 03:13:22 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 070A81005513; Wed, 25 Mar 2020 07:13:16 +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 CC46C60C05; Wed, 25 Mar 2020 07:13:15 +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 7075C1803C33; Wed, 25 Mar 2020 07:13:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02P7CU91023910 for ; Wed, 25 Mar 2020 03:12:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6064210F1C06; Wed, 25 Mar 2020 07:12:30 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5843D10F1CD9 for ; Wed, 25 Mar 2020 07:12:28 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A821A8007AC for ; Wed, 25 Mar 2020 07:12:28 +0000 (UTC) Received: from mail-m24147.qiye.163.com (mail-m24147.qiye.163.com [220.194.24.147]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-439-IaVF86RLOm-_o6mRZ0honA-1; Wed, 25 Mar 2020 03:12:24 -0400 Received: from localhost.localdomain (unknown [123.232.151.103]) by smtp4 (Coremail) with SMTP id JedpCgD3ftNNBHtey+koAw--.408S10; Wed, 25 Mar 2020 15:12:20 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585120404; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=uuI/9Av/7+3r/ZEsVbreeEvSEk1jWUB4R1XKgd1ZKtY=; b=ifxFIkUIw+PndCeECE/xwiULvpqmZaqw8lHksWiNaHM1aHDg5VPYi4VHYARAx879p1csVK nekNIC3vVn+/Upm4dH8K2q8TWFCnZjcC6xFBGrmwzTrmer2p1bC/2ZKPMAC/Y3y9YdNMuL X8oGssbbhhfxXvKqBaUIh5SDW9gN6yg= X-MC-Unique: fohCpBtpOc-o-TMyXpNv5w-1 X-MC-Unique: IaVF86RLOm-_o6mRZ0honA-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFC 08/29] util: Add a helper function virStrToLong_u8p Date: Wed, 25 Mar 2020 15:11:48 +0800 Message-Id: <20200325071209.20841-9-shi_lei@massclouds.com> In-Reply-To: <20200325071209.20841-1-shi_lei@massclouds.com> References: <20200325071209.20841-1-shi_lei@massclouds.com> X-CM-TRANSID: JedpCgD3ftNNBHtey+koAw--.408S10 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjTRSdgtUUUUU X-Originating-IP: [123.232.151.103] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiPhTxT1bdHEorqgAAsI X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 02P7CU91023910 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.79 on 10.5.11.12 X-Mimecast-Spam-Score: 2 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Meta 'U8' corresponds to 'uint8_t'. Add virStrToLong_u8p when parsing uint8_t. Signed-off-by: Shi Lei --- src/util/virstring.c | 15 +++++++++++++++ src/util/virstring.h | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/src/util/virstring.c b/src/util/virstring.c index 2d0bb23..83d13ff 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -460,6 +460,21 @@ virStrToLong_uip(char const *s, char **end_ptr, int ba= se, unsigned int *result) return 0; } =20 +/* Just like virStrToLong_uip, above, but produce an "uint8_t" value. + * This version rejects any negative signs. */ +int +virStrToLong_u8p(char const *s, char **end_ptr, int base, uint8_t *result) +{ + unsigned int val; + int ret; + ret =3D virStrToLong_uip(s, end_ptr, base, &val); + if (ret < 0 || val > 0xff) + return -1; + + *result =3D (uint8_t) val; + return 0; +} + /* Just like virStrToLong_i, above, but produce a "long" value. */ int virStrToLong_l(char const *s, char **end_ptr, int base, long *result) diff --git a/src/util/virstring.h b/src/util/virstring.h index c528e44..da73f86 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -77,6 +77,11 @@ int virStrToLong_uip(char const *s, int base, unsigned int *result) G_GNUC_WARN_UNUSED_RESULT; +int virStrToLong_u8p(char const *s, + char **end_ptr, + int base, + uint8_t *result) + G_GNUC_WARN_UNUSED_RESULT; int virStrToLong_l(char const *s, char **end_ptr, int base, --=20 2.17.1