util/cutils: Clean up variable names around qemu_strtol()

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.

Backports commit 717adf960933da0650d995f050d457063d591914 from qemu
This commit is contained in:
Markus Armbruster 2018-03-02 08:41:44 -05:00 committed by Lioncash
parent 41c2e1168f
commit 9236950e61
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7

View file

@ -209,21 +209,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, static int check_strtox_error(const char *nptr, char *ep,
int err) const char **endptr, int libc_errno)
{ {
if (err == 0 && endptr == p) { if (libc_errno == 0 && ep == nptr) {
err = EINVAL; libc_errno = EINVAL;
} }
if (!next && *endptr) { if (!endptr && *ep) {
return -EINVAL; return -EINVAL;
} }
if (next) { if (endptr) {
*next = endptr; *endptr = ep;
} }
return -err; return -libc_errno;
} }
/** /**
@ -253,7 +253,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, int qemu_strtol(const char *nptr, const char **endptr, int base,
long *result) long *result)
{ {
char *p; char *ep;
int err = 0; int err = 0;
if (!nptr) { if (!nptr) {
if (endptr) { if (endptr) {
@ -262,8 +262,8 @@ int qemu_strtol(const char *nptr, const char **endptr, int base,
err = -EINVAL; err = -EINVAL;
} else { } else {
errno = 0; errno = 0;
*result = strtol(nptr, &p, base); *result = strtol(nptr, &ep, base);
err = check_strtox_error(nptr, p, endptr, errno); err = check_strtox_error(nptr, ep, endptr, errno);
} }
return err; return err;
} }
@ -296,7 +296,7 @@ int qemu_strtol(const char *nptr, const char **endptr, int base,
int qemu_strtoul(const char *nptr, const char **endptr, int base, int qemu_strtoul(const char *nptr, const char **endptr, int base,
unsigned long *result) unsigned long *result)
{ {
char *p; char *ep;
int err = 0; int err = 0;
if (!nptr) { if (!nptr) {
if (endptr) { if (endptr) {
@ -305,12 +305,12 @@ int qemu_strtoul(const char *nptr, const char **endptr, int base,
err = -EINVAL; err = -EINVAL;
} else { } else {
errno = 0; errno = 0;
*result = strtoul(nptr, &p, base); *result = strtoul(nptr, &ep, base);
/* Windows returns 1 for negative out-of-range values. */ /* Windows returns 1 for negative out-of-range values. */
if (errno == ERANGE) { if (errno == ERANGE) {
*result = -1; *result = -1;
} }
err = check_strtox_error(nptr, p, endptr, errno); err = check_strtox_error(nptr, ep, endptr, errno);
} }
return err; return err;
} }
@ -324,7 +324,7 @@ int qemu_strtoul(const char *nptr, const char **endptr, int base,
int qemu_strtoi64(const char *nptr, const char **endptr, int base, int qemu_strtoi64(const char *nptr, const char **endptr, int base,
int64_t *result) int64_t *result)
{ {
char *p; char *ep;
int err = 0; int err = 0;
if (!nptr) { if (!nptr) {
if (endptr) { if (endptr) {
@ -334,8 +334,8 @@ int qemu_strtoi64(const char *nptr, const char **endptr, int base,
} else { } else {
errno = 0; errno = 0;
/* FIXME This assumes int64_t is long long */ /* FIXME This assumes int64_t is long long */
*result = strtoll(nptr, &p, base); *result = strtoll(nptr, &ep, base);
err = check_strtox_error(nptr, p, endptr, errno); err = check_strtox_error(nptr, ep, endptr, errno);
} }
return err; return err;
} }
@ -348,7 +348,7 @@ int qemu_strtoi64(const char *nptr, const char **endptr, int base,
int qemu_strtou64(const char *nptr, const char **endptr, int base, int qemu_strtou64(const char *nptr, const char **endptr, int base,
uint64_t *result) uint64_t *result)
{ {
char *p; char *ep;
int err = 0; int err = 0;
if (!nptr) { if (!nptr) {
if (endptr) { if (endptr) {
@ -358,12 +358,12 @@ int qemu_strtou64(const char *nptr, const char **endptr, int base,
} else { } else {
errno = 0; errno = 0;
/* FIXME This assumes uint64_t is unsigned long long */ /* 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. */ /* Windows returns 1 for negative out-of-range values. */
if (errno == ERANGE) { if (errno == ERANGE) {
*result = -1; *result = -1;
} }
err = check_strtox_error(nptr, p, endptr, errno); err = check_strtox_error(nptr, ep, endptr, errno);
} }
return err; return err;
} }