1 /******************************************************************************
2 * Copyright (c) 2004, 2008 IBM Corporation
4 * This program and the accompanying materials
5 * are made available under the terms of the BSD License
6 * which accompanies this distribution, and is available at
7 * http://www.opensource.org/licenses/bsd-license.php
10 * IBM Corporation - initial implementation
11 *****************************************************************************/
15 unsigned long int strtoul(const char *S, char **PTR,int BASE)
17 unsigned long rval = 0;
19 // *PTR is S, unless PTR is NULL, in which case i override it with my own ptr
26 // i use PTR to advance through the string
29 if ((BASE < 0) || BASE > 36)
33 // ignore white space at beginning of S
42 // if BASE is 0... determine the base from the first chars...
45 // if S starts with "0x", BASE = 16, else 10
46 if ((**PTR == '0') && (*((*PTR)+1) == 'x'))
59 // S may start with "0x"
60 if ((**PTR == '0') && (*((*PTR)+1) == 'x'))
69 if (((**PTR) >= '0') && ((**PTR) <='9'))
74 else if (((**PTR) >= 'a') && ((**PTR) <='z'))
76 //alphanumeric digit lowercase(a (10) .. z (35) )
77 digit = (**PTR - 'a') + 10;
79 else if (((**PTR) >= 'A') && ((**PTR) <='Z'))
81 //alphanumeric digit uppercase(a (10) .. z (35) )
82 digit = (**PTR - 'A') + 10;
86 //end of parseable number reached...
91 rval = (rval * BASE) + digit;
95 //digit found, but its too big for current base
96 //end of parseable number reached...