home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / pub / palmos / pippy-0.6beta-src.tar.gz / pippy-0.6beta-src.tar / pippy-0.6beta-src / src / Palm / libc / strtol.c < prev    next >
C/C++ Source or Header  |  2000-12-21  |  816b  |  47 lines

  1. /*
  2.  *  linux/lib/string.c
  3.  *
  4.  *  Copyright (C) 1991, 1992  Linus Torvalds
  5.  */
  6.  
  7. #include <sys/types.h>
  8. #include <string.h>
  9. #include <ctype.h>
  10.  
  11.  
  12. #ifndef __HAVE_ARCH_STRTOL
  13. signed long strtol(const char *cp,char **endp,unsigned int base)
  14. {
  15.   signed long sign;
  16.   signed long result = 0,value;
  17.   if (!isdigit(*cp))
  18.     {
  19.       if ((*cp) == '-')
  20.     sign = -1;
  21.       else
  22.     sign = 1;
  23.       cp++;
  24.     }
  25.   else sign = 1;
  26.   if (!base) {
  27.     base = 10;
  28.     if (*cp == '0') {
  29.       base = 8;
  30.       cp++;
  31.       if ((*cp == 'x') && isxdigit(cp[1])) {
  32.     cp++;
  33.     base = 16;
  34.       }
  35.     }
  36.   }
  37.   while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp)
  38.                                  ? toupper(*cp) : *cp)-'A'+10) < base) {
  39.     result = result*base + value;
  40.     cp++;
  41.   }
  42.   if (endp)
  43.     *endp = (char *)cp;
  44.   return (result * sign);
  45. }
  46. #endif
  47.