summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/dietlibc/lib/atoi.c
blob: 10b6189508923908150da5f138ec2e6d0d748928 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <endian.h>
#include <ctype.h>
#include <stdlib.h>

#if __WORDSIZE == 64
int atoi(const char* s) {
  long int v=0;
  int sign=1;
  while ( *s == ' '  ||  (unsigned int)(*s - 9) < 5u) s++;
  switch (*s) {
  case '-': sign=-1;
  case '+': ++s;
  }
  while ((unsigned int) (*s - '0') < 10u) {
    v=v*10+*s-'0'; ++s;
  }
  return sign==-1?-v:v;
}
#endif