blob: d77a8cdefc193df9c9aeb2756e8305deb8e3d664 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
int sign, flag = 0;
signed char sym;
/* Check for valid base and zero out read size */
result = 0;
if (actual)
*actual = 0;
if (base != 0 && (base < 2 || base > 36))
return 0;
/* Handle space, sign and base */
skipSpace(&string, actual);
handleSign(&string, actual, &sign);
guessBase(&string, actual, &base);
/* Read digits */
while(*string)
{
sym = *(string++);
sym = lookup[(unsigned int)sym];
if (sym >= base || sym == -1)
break;
if (actual)
(*actual)++;
result = result * base + sym;
flag = 1;
}
/* Zero out size on error */
if (!result && !flag && actual)
*actual = 0;
return result * sign;
|