qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Tao Xu <tao3.xu@intel.com>
To: mst@redhat.com, imammedo@redhat.com, eblake@redhat.com,
	ehabkost@redhat.com, marcel.apfelbaum@gmail.com,
	armbru@redhat.com, mdroth@linux.vnet.ibm.com, thuth@redhat.com,
	lvivier@redhat.com
Cc: jingqi.liu@intel.com, tao3.xu@intel.com, fan.du@intel.com,
	qemu-devel@nongnu.org, jonathan.cameron@huawei.com
Subject: [PATCH v16 01/14] util/cutils: Add Add qemu_strtold and qemu_strtold_finite
Date: Fri, 15 Nov 2019 15:53:39 +0800	[thread overview]
Message-ID: <20191115075352.17734-2-tao3.xu@intel.com> (raw)
In-Reply-To: <20191115075352.17734-1-tao3.xu@intel.com>

Work like qemu_strtod() and qemu_strtold_finite, except store long
double.

Signed-off-by: Tao Xu <tao3.xu@intel.com>
---

New patch in v16.
---
 include/qemu/cutils.h |  3 +++
 util/cutils.c         | 48 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
index b54c847e0f..48cf9bf776 100644
--- a/include/qemu/cutils.h
+++ b/include/qemu/cutils.h
@@ -146,6 +146,9 @@ 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);
 int qemu_strtod_finite(const char *nptr, const char **endptr, double *result);
+int qemu_strtold(const char *nptr, const char **endptr, long double *result);
+int qemu_strtold_finite(const char *nptr, const char **endptr,
+                        long double *result);
 
 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 fd591cadf0..5db3b2add5 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -553,7 +553,7 @@ int qemu_strtou64(const char *nptr, const char **endptr, int base,
 
 /**
  * Convert string @nptr to a double.
-  *
+ *
  * This is a wrapper around strtod() that is harder to misuse.
  * Semantics of @nptr and @endptr match strtod() with differences
  * noted below.
@@ -616,6 +616,52 @@ int qemu_strtod_finite(const char *nptr, const char **endptr, double *result)
     return ret;
 }
 
+/*
+ * Convert string @nptr to a long double.
+ *
+ * Works like qemu_strtod(), except it stores long double.
+ */
+int qemu_strtold(const char *nptr, const char **endptr, long double *result)
+{
+    char *ep;
+
+    if (!nptr) {
+        if (endptr) {
+            *endptr = nptr;
+        }
+        return -EINVAL;
+    }
+
+    errno = 0;
+    *result = strtold(nptr, &ep);
+    return check_strtox_error(nptr, ep, endptr, errno);
+}
+
+/*
+ * Convert string @nptr to a finite long double.
+ *
+ * Works like qemu_strtod_finite(), except it stores long double.
+ */
+int qemu_strtold_finite(const char *nptr, const char **endptr,
+                        long double *result)
+{
+    long double tmp;
+    int ret;
+
+    ret = qemu_strtold(nptr, endptr, &tmp);
+    if (!ret && !isfinite(tmp)) {
+        if (endptr) {
+            *endptr = nptr;
+        }
+        ret = -EINVAL;
+    }
+
+    if (ret != -EINVAL) {
+        *result = tmp;
+    }
+    return ret;
+}
+
 /**
  * Searches for the first occurrence of 'c' in 's', and returns a pointer
  * to the trailing null byte if none was found.
-- 
2.20.1



  reply	other threads:[~2019-11-15  7:56 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-15  7:53 [PATCH v16 00/14] Build ACPI Heterogeneous Memory Attribute Table (HMAT) Tao Xu
2019-11-15  7:53 ` Tao Xu [this message]
2019-11-15  7:53 ` [PATCH v16 02/14] util/cutils: Use qemu_strtold_finite to parse size Tao Xu
2019-11-15  7:53 ` [PATCH v16 03/14] util/cutils: refactor do_strtosz() to support suffixes list Tao Xu
2019-11-15 12:11   ` Philippe Mathieu-Daudé
2019-11-18  7:35     ` Tao Xu
2019-11-15  7:53 ` [PATCH v16 04/14] util/cutils: Add qemu_strtotime_ns() Tao Xu
2019-11-15  7:53 ` [PATCH v16 05/14] qapi: Add builtin type time Tao Xu
2019-11-15  7:53 ` [PATCH v16 06/14] tests: Add test for QAPI " Tao Xu
2019-11-15  7:53 ` [PATCH v16 07/14] numa: Extend CLI to provide initiator information for numa nodes Tao Xu
2019-11-15  7:53 ` [PATCH v16 08/14] numa: Extend CLI to provide memory latency and bandwidth information Tao Xu
2019-11-19 11:03   ` Igor Mammedov
2019-11-20  7:55     ` Tao Xu
2019-11-20 12:56       ` Igor Mammedov
2019-11-21  1:07         ` Tao Xu
2019-11-15  7:53 ` [PATCH v16 09/14] numa: Extend CLI to provide memory side cache information Tao Xu
2019-11-19 11:47   ` Igor Mammedov
2019-11-20  6:51     ` Tao Xu
2019-11-15  7:53 ` [PATCH v16 10/14] hmat acpi: Build Memory Proximity Domain Attributes Structure(s) Tao Xu
2019-11-15  7:53 ` [PATCH v16 11/14] hmat acpi: Build System Locality Latency and Bandwidth Information Structure(s) Tao Xu
2019-11-20 10:09   ` Igor Mammedov
2019-11-21  1:28     ` Tao Xu
2019-11-15  7:53 ` [PATCH v16 12/14] hmat acpi: Build Memory Side Cache " Tao Xu
2019-11-20 12:50   ` Igor Mammedov
2019-11-15  7:53 ` [PATCH v16 13/14] tests/numa: Add case for QMP build HMAT Tao Xu
2019-11-20 12:32   ` Igor Mammedov
2019-11-21  0:56     ` Tao Xu
2019-11-15  7:53 ` [PATCH v16 14/14] tests/bios-tables-test: add test cases for ACPI HMAT Tao Xu
2019-11-15  8:58 ` [PATCH v16 00/14] Build ACPI Heterogeneous Memory Attribute Table (HMAT) no-reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191115075352.17734-2-tao3.xu@intel.com \
    --to=tao3.xu@intel.com \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=fan.du@intel.com \
    --cc=imammedo@redhat.com \
    --cc=jingqi.liu@intel.com \
    --cc=jonathan.cameron@huawei.com \
    --cc=lvivier@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).