atoi.c 435 B

12345678910111213141516
  1. #include <stdlib.h>
  2. #include <ctype.h>
  3. #ifndef CONFIRM_REGPARM1_ENABLED
  4. #error You need to patch <default.h> as described in the 'COMPILING' file.
  5. #endif
  6. __ATTR_LIB_C__ short atoi(const char *s)
  7. {
  8. unsigned short c,value=0,neg=0;
  9. while(*s==' ') ++s;
  10. if(*s=='-'||*(const unsigned char*)s==0xAD) ++s,neg=-1;
  11. else if(*s=='+') ++s;
  12. while(isdigit(c=*(const unsigned char*)s++)) value=10*value+c-'0';
  13. return neg?-value:value;
  14. }