ref: 60e5ff036844491e3ad78a4254171c218dec98c9
parent: c2f5b177c6ada717746917581b5d3d98e1ab91a0
author: Quentin Rameau <quinq@fifth.space>
date: Sat Dec 29 05:20:52 EST 2018
[libc] Use _dtoi for atoi family too
--- a/src/libc/stdlib/atoi.c
+++ b/src/libc/stdlib/atoi.c
@@ -5,7 +5,7 @@
int
atoi(const char *s)
{
- int n, sign = -1;
+ int n, d, sign = -1;
while (isspace(*s))
++s;
@@ -18,8 +18,8 @@
}
/* Compute n as a negative number to avoid overflow on INT_MIN */
- for (n = 0; isdigit(*s); ++s)
- n = 10*n - (*s - '0');
+ for (n = 0; (d = _dtoi(*s)) < 10; ++s)
+ n = n*10 - d;
return sign * n;
}
--- a/src/libc/stdlib/atol.c
+++ b/src/libc/stdlib/atol.c
@@ -5,7 +5,7 @@
long
atol(const char *s)
{
- int sign = -1;
+ int d, sign = -1;
long n;
while (isspace(*s))
@@ -19,8 +19,8 @@
}
/* Compute n as a negative number to avoid overflow on LONG_MIN */
- for (n = 0; isdigit(*s); ++s)
- n = 10*n - (*s - '0');
+ for (n = 0; (d = _dtoi(*s)) < 10; ++s)
+ n = n*10 - d;
return sign * n;
}
--- a/src/libc/stdlib/atoll.c
+++ b/src/libc/stdlib/atoll.c
@@ -5,7 +5,7 @@
long long
atoll(const char *s)
{
- int sign = -1;
+ int d, sign = -1;
long long n;
while (isspace(*s))
@@ -19,8 +19,8 @@
}
/* Compute n as a negative number to avoid overflow on LLONG_MIN */
- for (n = 0; isdigit(*s); ++s)
- n = 10*n - (*s - '0');
+ for (n = 0; (d = _dtoi(*s)) < 10; ++s)
+ n = n*10 - d;
return sign * n;
}