Skip to content

Commit

Permalink
Clean up atoi.c atol.c
Browse files Browse the repository at this point in the history
  • Loading branch information
ghaerr committed Oct 15, 2024
1 parent 9b726bc commit f14dee3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
1 change: 0 additions & 1 deletion libc/misc/atoi.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <stdlib.h>
#include <ctype.h>

int atoi(const char *s)
{
Expand Down
23 changes: 11 additions & 12 deletions libc/misc/atol.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
#include <stdlib.h>
#include <ctype.h>

long atol(const char *s)
{
long n = 0;
int neg = 0;
long n = 0;
int neg = 0;

while (*s == ' ' || *s == '\t')
s++;
switch (*s) {
case '-': neg = 1;
case '+': s++;
}
while ((unsigned) (*s - '0') <= 9u)
n = n * 10 + *s++ - '0';
return neg ? 0u - n : n;
while (*s == ' ' || *s == '\t')
s++;
switch (*s) {
case '-': neg = 1;
case '+': s++;
}
while ((unsigned) (*s - '0') <= 9u)
n = n * 10 + *s++ - '0';
return neg ? 0u - n : n;
}

0 comments on commit f14dee3

Please sign in to comment.