atol.c 339 B

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