From nobody Mon Feb 9 10:28:02 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541761677436197.86479383605513; Fri, 9 Nov 2018 03:07:57 -0800 (PST) Received: from localhost ([::1]:33184 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gL4do-0000L4-8r for importer@patchew.org; Fri, 09 Nov 2018 06:07:56 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34274) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gL4Yp-00046s-Fl for qemu-devel@nongnu.org; Fri, 09 Nov 2018 06:02:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gL4Yl-0004PP-Ep for qemu-devel@nongnu.org; Fri, 09 Nov 2018 06:02:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56722) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gL4Yl-0004C6-4L for qemu-devel@nongnu.org; Fri, 09 Nov 2018 06:02:43 -0500 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 mx1.redhat.com (Postfix) with ESMTPS id 261A43002507; Fri, 9 Nov 2018 11:02:28 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-228.ams2.redhat.com [10.36.116.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id B044D5FCBD; Fri, 9 Nov 2018 11:02:26 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Fri, 9 Nov 2018 12:02:16 +0100 Message-Id: <20181109110221.10553-2-david@redhat.com> In-Reply-To: <20181109110221.10553-1-david@redhat.com> References: <20181109110221.10553-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 09 Nov 2018 11:02:28 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH RFC 1/6] cutils: add qemu_strtod() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , David Hildenbrand , Markus Armbruster , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Let's provide a wrapper for strtod(). Signed-off-by: David Hildenbrand --- include/qemu/cutils.h | 1 + util/cutils.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h index 7071bfe2d4..84fb9e53c6 100644 --- a/include/qemu/cutils.h +++ b/include/qemu/cutils.h @@ -146,6 +146,7 @@ int qemu_strtoi64(const char *nptr, const char **endptr= , int base, int64_t *result); int qemu_strtou64(const char *nptr, const char **endptr, int base, uint64_t *result); +int qemu_strtod(const char *nptr, const char **endptr, double *result); =20 int parse_uint(const char *s, unsigned long long *value, char **endptr, int base); diff --git a/util/cutils.c b/util/cutils.c index 698bd315bd..850e3af9ea 100644 --- a/util/cutils.c +++ b/util/cutils.c @@ -544,6 +544,28 @@ int qemu_strtou64(const char *nptr, const char **endpt= r, int base, return check_strtox_error(nptr, ep, endptr, errno); } =20 +/** + * Convert string @nptr to a double. + * + * Works like qemu_strtoul(), except it stores +/-HUGE_VAL on + * overflow/underflow. + */ +int qemu_strtod(const char *nptr, const char **endptr, double *result) +{ + char *ep; + + if (!nptr) { + if (endptr) { + *endptr =3D nptr; + } + return -EINVAL; + } + + errno =3D 0; + *result =3D strtod(nptr, &ep); + return check_strtox_error(nptr, ep, endptr, errno); +} + /** * Searches for the first occurrence of 'c' in 's', and returns a pointer * to the trailing null byte if none was found. --=20 2.17.2