summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorCarlos L. Torres <carlos.torres@rackspace.com>2015-07-19 18:02:19 -0500
committerPaolo Bonzini <pbonzini@redhat.com>2015-09-09 15:34:54 +0200
commit8ac4df40cc5de606a8ac9174e2340c21093b4e3b (patch)
treedbc6bf4eb2de63a72b86be0872a5d3194734d7c5 /util
parentc817c01548b1500753d0bea3852938d919161778 (diff)
cutils: Add qemu_strtoll() wrapper
Add wrapper for strtoll() function. Include unit tests. Signed-off-by: Carlos L. Torres <carlos.torres@rackspace.com> Message-Id: <7454a6bb9ec03b629e8beb4f109dd30dc2c9804c.1437346779.git.carlos.torres@rackspace.com> [Use int64_t in prototype, since that's what QEMU uses. - Paolo] Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'util')
-rw-r--r--util/cutils.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/util/cutils.c b/util/cutils.c
index 8ee3d5ee9d..7084d6f1ce 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -449,6 +449,29 @@ int qemu_strtoul(const char *nptr, const char **endptr, int base,
}
/**
+ * Converts ASCII string to a long long integer.
+ *
+ * See qemu_strtol() documentation for more info.
+ */
+int qemu_strtoll(const char *nptr, const char **endptr, int base,
+ int64_t *result)
+{
+ char *p;
+ int err = 0;
+ if (!nptr) {
+ if (endptr) {
+ *endptr = nptr;
+ }
+ err = -EINVAL;
+ } else {
+ errno = 0;
+ *result = strtoll(nptr, &p, base);
+ err = check_strtox_error(endptr, p, errno);
+ }
+ return err;
+}
+
+/**
* parse_uint:
*
* @s: String to parse