scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

atoll.c (353B)


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