commit efc025bc3038571204f54c10aa73921ef898d2c1
parent c65211248fca64724baa92e125955408971080f9
Author: Quentin Rameau <quinq@fifth.space>
Date: Sat, 29 Dec 2018 10:20:52 +0100
[libc] Use _dtoi for atoi family too
Diffstat:
3 files changed, 9 insertions(+), 9 deletions(-)
diff --git 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 @@ atoi(const char *s)
}
/* 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;
}
diff --git 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 @@ atol(const char *s)
}
/* 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;
}
diff --git 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 @@ atoll(const char *s)
}
/* 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;
}