Home
       atoi.c - scc - simple c99 compiler
  HTML git clone git://git.simple-cc.org/scc
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
   DIR README
   DIR LICENSE
       ---
       atoi.c (357B)
       ---
            1 #include <ctype.h>
            2 #include <stdlib.h>
            3 
            4 #include "../libc.h"
            5 
            6 #undef atoi
            7 
            8 int
            9 atoi(const char *s)
           10 {
           11         int n, d, sign = -1;
           12 
           13         while (isspace(*s))
           14                 ++s;
           15 
           16         switch (*s) {
           17         case '-':
           18                 sign = 1;
           19         case '+':
           20                 ++s;
           21         }
           22 
           23         /* Compute n as a negative number to avoid overflow on INT_MIN */
           24         for (n = 0; (d = _dtoi(*s)) < 10; ++s)
           25                 n = n*10 - d;
           26 
           27         return sign * n;
           28 }