scc

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

atoi.c (332B)


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