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 / strtoul.c < prev    next >
C/C++ Source or Header  |  2000-12-21  |  663b  |  36 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. #ifndef __HAVE_ARCH_STRTOUL
  12. unsigned long strtoul(const char *cp,char **endp,unsigned int base)
  13. {
  14.   unsigned long result = 0,value;
  15.   
  16.   if (!base) {
  17.     base = 10;
  18.     if (*cp == '0') {
  19.       base = 8;
  20.       cp++;
  21.       if ((*cp == 'x') && isxdigit(cp[1])) {
  22.     cp++;
  23.     base = 16;
  24.       }
  25.     }
  26.   }
  27.   while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp) ? toupper(*cp) : *cp)-'A'+10) < base) {
  28.     result = result*base + value;
  29.     cp++;
  30.   }
  31.   if (endp)
  32.     *endp = (char *)cp;
  33.   return result;
  34. }
  35. #endif
  36.