[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 07/24] util/cutils: Clean up variable names aroun
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PATCH v2 07/24] util/cutils: Clean up variable names around qemu_strtol() |
Date: |
Tue, 21 Feb 2017 21:13:51 +0100 |
Name same things the same, different things differently.
* qemu_strtol()'s parameter @nptr is called @p in
check_strtox_error(). Rename the latter.
* qemu_strtol()'s parameter @endptr is called @next in
check_strtox_error(). Rename the latter.
* qemu_strtol()'s variable @p is called @endptr in
check_strtox_error(). Rename both to @ep.
* qemu_strtol()'s variable @err is *negative* errno,
check_strtox_error()'s parameter @err is *positive*. Rename the
latter to @libc_errno.
Same for qemu_strtoul(), qemu_strtoi64(), qemu_strtou64(), of course.
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
util/cutils.c | 42 +++++++++++++++++++++---------------------
1 file changed, 21 insertions(+), 21 deletions(-)
diff --git a/util/cutils.c b/util/cutils.c
index 0dc9b28..0fb0f82 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -260,21 +260,21 @@ int64_t qemu_strtosz(const char *nptr, char **end)
}
/**
- * Helper function for qemu_strto*l() functions.
+ * Helper function for error checking after strtol() and the like
*/
-static int check_strtox_error(const char *p, char *endptr, const char **next,
- int err)
+static int check_strtox_error(const char *nptr, char *ep,
+ const char **endptr, int libc_errno)
{
- if (err == 0 && endptr == p) {
- err = EINVAL;
+ if (libc_errno == 0 && ep == nptr) {
+ libc_errno = EINVAL;
}
- if (!next && *endptr) {
+ if (!endptr && *ep) {
return -EINVAL;
}
- if (next) {
- *next = endptr;
+ if (endptr) {
+ *endptr = ep;
}
- return -err;
+ return -libc_errno;
}
/**
@@ -304,7 +304,7 @@ static int check_strtox_error(const char *p, char *endptr,
const char **next,
int qemu_strtol(const char *nptr, const char **endptr, int base,
long *result)
{
- char *p;
+ char *ep;
int err = 0;
if (!nptr) {
if (endptr) {
@@ -313,8 +313,8 @@ int qemu_strtol(const char *nptr, const char **endptr, int
base,
err = -EINVAL;
} else {
errno = 0;
- *result = strtol(nptr, &p, base);
- err = check_strtox_error(nptr, p, endptr, errno);
+ *result = strtol(nptr, &ep, base);
+ err = check_strtox_error(nptr, ep, endptr, errno);
}
return err;
}
@@ -347,7 +347,7 @@ int qemu_strtol(const char *nptr, const char **endptr, int
base,
int qemu_strtoul(const char *nptr, const char **endptr, int base,
unsigned long *result)
{
- char *p;
+ char *ep;
int err = 0;
if (!nptr) {
if (endptr) {
@@ -356,12 +356,12 @@ int qemu_strtoul(const char *nptr, const char **endptr,
int base,
err = -EINVAL;
} else {
errno = 0;
- *result = strtoul(nptr, &p, base);
+ *result = strtoul(nptr, &ep, base);
/* Windows returns 1 for negative out-of-range values. */
if (errno == ERANGE) {
*result = -1;
}
- err = check_strtox_error(nptr, p, endptr, errno);
+ err = check_strtox_error(nptr, ep, endptr, errno);
}
return err;
}
@@ -375,7 +375,7 @@ int qemu_strtoul(const char *nptr, const char **endptr, int
base,
int qemu_strtoi64(const char *nptr, const char **endptr, int base,
int64_t *result)
{
- char *p;
+ char *ep;
int err = 0;
if (!nptr) {
if (endptr) {
@@ -385,8 +385,8 @@ int qemu_strtoi64(const char *nptr, const char **endptr,
int base,
} else {
errno = 0;
/* FIXME This assumes int64_t is long long */
- *result = strtoll(nptr, &p, base);
- err = check_strtox_error(nptr, p, endptr, errno);
+ *result = strtoll(nptr, &ep, base);
+ err = check_strtox_error(nptr, ep, endptr, errno);
}
return err;
}
@@ -399,7 +399,7 @@ int qemu_strtoi64(const char *nptr, const char **endptr,
int base,
int qemu_strtou64(const char *nptr, const char **endptr, int base,
uint64_t *result)
{
- char *p;
+ char *ep;
int err = 0;
if (!nptr) {
if (endptr) {
@@ -409,12 +409,12 @@ int qemu_strtou64(const char *nptr, const char **endptr,
int base,
} else {
errno = 0;
/* FIXME This assumes uint64_t is unsigned long long */
- *result = strtoull(nptr, &p, base);
+ *result = strtoull(nptr, &ep, base);
/* Windows returns 1 for negative out-of-range values. */
if (errno == ERANGE) {
*result = -1;
}
- err = check_strtox_error(nptr, p, endptr, errno);
+ err = check_strtox_error(nptr, ep, endptr, errno);
}
return err;
}
--
2.7.4
- [Qemu-devel] [PATCH v2 00/24] QemuOpts util/cutils: Fix and clean up number conversions, Markus Armbruster, 2017/02/21
- [Qemu-devel] [PATCH v2 04/24] test-cutils: Clean up qemu_strtoul() result checks, Markus Armbruster, 2017/02/21
- [Qemu-devel] [PATCH v2 17/24] util/cutils: Drop QEMU_STRTOSZ_DEFSUFFIX_* macros, Markus Armbruster, 2017/02/21
- [Qemu-devel] [PATCH v2 01/24] test-qemu-opts: Cover qemu_opts_parse(), Markus Armbruster, 2017/02/21
- [Qemu-devel] [PATCH v2 07/24] util/cutils: Clean up variable names around qemu_strtol(),
Markus Armbruster <=
- [Qemu-devel] [PATCH v2 11/24] test-cutils: Cover qemu_strtosz() invalid input, Markus Armbruster, 2017/02/21
- [Qemu-devel] [PATCH v2 10/24] test-cutils: Add missing qemu_strtosz()... endptr checks, Markus Armbruster, 2017/02/21
- [Qemu-devel] [PATCH v2 05/24] util/cutils: Rewrite documentation of qemu_strtol() & friends, Markus Armbruster, 2017/02/21
- [Qemu-devel] [PATCH v2 12/24] test-cutils: Cover qemu_strtosz() with trailing crap, Markus Armbruster, 2017/02/21
- [Qemu-devel] [PATCH v2 08/24] util/cutils: Clean up control flow around qemu_strtol() a bit, Markus Armbruster, 2017/02/21
- [Qemu-devel] [PATCH v2 03/24] test-cutils: Add missing qemu_strtol()... endptr checks, Markus Armbruster, 2017/02/21
- [Qemu-devel] [PATCH v2 19/24] test-cutils: Drop suffix from test_qemu_strtosz_simple(), Markus Armbruster, 2017/02/21
- [Qemu-devel] [PATCH v2 13/24] test-cutils: Cover qemu_strtosz() around range limits, Markus Armbruster, 2017/02/21
- [Qemu-devel] [PATCH v2 09/24] option: Fix to reject invalid and overflowing numbers, Markus Armbruster, 2017/02/21
- [Qemu-devel] [PATCH v2 02/24] option: Assert value string isn't null, Markus Armbruster, 2017/02/21