summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/utils/xatonum.cpp56
1 files changed, 28 insertions, 28 deletions
diff --git a/lib/utils/xatonum.cpp b/lib/utils/xatonum.cpp
index 83146298..3b22071f 100644
--- a/lib/utils/xatonum.cpp
+++ b/lib/utils/xatonum.cpp
@@ -9,42 +9,42 @@
unsigned xatou(const char *numstr)
{
- unsigned long r;
- int old_errno;
- char *e;
-
- if (*numstr < '0' || *numstr > '9')
- goto inval;
-
- old_errno = errno;
- errno = 0;
- r = strtoul(numstr, &e, 10);
- if (errno || numstr == e || *e != '\0' || r > UINT_MAX)
- goto inval; /* error / no digits / illegal trailing chars */
- errno = old_errno; /* Ok. So restore errno. */
- return r;
-
- inval:
- error_msg_and_die("invalid number '%s'", numstr);
+ unsigned long r;
+ int old_errno;
+ char *e;
+
+ if (*numstr < '0' || *numstr > '9')
+ goto inval;
+
+ old_errno = errno;
+ errno = 0;
+ r = strtoul(numstr, &e, 10);
+ if (errno || numstr == e || *e != '\0' || r > UINT_MAX)
+ goto inval; /* error / no digits / illegal trailing chars */
+ errno = old_errno; /* Ok. So restore errno. */
+ return r;
+
+inval:
+ error_msg_and_die("invalid number '%s'", numstr);
}
int xatoi_u(const char *numstr)
{
- unsigned r = xatou(numstr);
- if (r > (unsigned)INT_MAX)
- error_msg_and_die("invalid number '%s'", numstr);
- return r;
+ unsigned r = xatou(numstr);
+ if (r > (unsigned)INT_MAX)
+ error_msg_and_die("invalid number '%s'", numstr);
+ return r;
}
int xatoi(const char *numstr)
{
- unsigned r;
+ unsigned r;
- if (*numstr != '-')
- return xatoi_u(numstr);
+ if (*numstr != '-')
+ return xatoi_u(numstr);
- r = xatou(numstr + 1);
- if (r > (unsigned)INT_MAX + 1)
- error_msg_and_die("invalid number '%s'", numstr);
- return - (int)r;
+ r = xatou(numstr + 1);
+ if (r > (unsigned)INT_MAX + 1)
+ error_msg_and_die("invalid number '%s'", numstr);
+ return - (int)r;
}