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 long int strtol(const char *S, char **PTR,int BASE)
18 short int negative = 0;
20 // *PTR is S, unless PTR is NULL, in which case i override it with my own ptr
27 // i use PTR to advance through the string
30 if ((BASE < 0) || BASE > 36)
34 // ignore white space at beginning of S
43 // check if S starts with "-" in which case the return value is negative
49 // if BASE is 0... determine the base from the first chars...
52 // if S starts with "0x", BASE = 16, else 10
53 if ((**PTR == '0') && (*((*PTR)+1) == 'x'))
66 // S may start with "0x"
67 if ((**PTR == '0') && (*((*PTR)+1) == 'x'))
76 if (((**PTR) >= '0') && ((**PTR) <= '9'))
81 else if (((**PTR) >= 'a') && ((**PTR) <='z'))
83 //alphanumeric digit lowercase(a (10) .. z (35) )
84 digit = (**PTR - 'a') + 10;
86 else if (((**PTR) >= 'A') && ((**PTR) <='Z'))
88 //alphanumeric digit uppercase(a (10) .. z (35) )
89 digit = (**PTR - 'A') + 10;
93 //end of parseable number reached...
98 rval = (rval * BASE) + digit;
102 //digit found, but its too big for current base
103 //end of parseable number reached...