atoi.c 319 B

123456789101112
  1. #include <stdlib.h>
  2. #include <ctype.h>
  3. __ATTR_LIB_C__ short atoi(const char *s)
  4. {
  5. unsigned short c,value=0,neg=0;
  6. while(*s==' ') ++s;
  7. if(*s=='-'||*(const unsigned char*)s==0xAD) ++s,neg=-1;
  8. else if(*s=='+') ++s;
  9. while(isdigit(c=*(const unsigned char*)s++)) value=10*value+c-'0';
  10. return neg?-value:value;
  11. }