atoll.c (378B)
1 #include <ctype.h> 2 #include <stdlib.h> 3 4 #include "../libc.h" 5 6 #undef atoll 7 8 long long 9 atoll(const char *s) 10 { 11 int d, sign = -1; 12 long long n; 13 14 while (isspace(*s)) 15 ++s; 16 17 switch (*s) { 18 case '-': 19 sign = 1; 20 case '+': 21 ++s; 22 } 23 24 /* Compute n as a negative number to avoid overflow on LLONG_MIN */ 25 for (n = 0; (d = _dtoi(*s)) < 10; ++s) 26 n = n*10 - d; 27 28 return sign * n; 29 }