blob: 57eaee0d694d2d8e00a0bd287b69a5ae394cffc3 (
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 (size)
*size = 0;
if (base != 0 && (base < 2 || base > 36))
return 0;
/* Handle space, sign and base */
skipSpace(&string, size);
handleSign(&string, size, &sign);
guessBase(&string, size, &base);
/* Read digits */
while(*string)
{
sym = *(string++);
sym = lookup[(unsigned int)sym];
if (sym >= base || sym == -1)
break;
if (size)
(*size)++;
result = result * base + sym;
flag = 1;
}
/* Zero out size on error */
if (!result && !flag && size)
*size = 0;
return result * sign;
|