summaryrefslogtreecommitdiff
path: root/src/stdlib/_strtoi.h
blob: 7a2d5cdf828193d075b28dced2c23d9b15199022 (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
35
36
37
38
39
40
41
42
43
	/* int iswide = (sizeof(*nptr) == sizeof(wchar_t)); */
	(void)max;
	
	if (base == 0) {
		/* determine base from prefix */
	}

	if (min == 0) {
		/* unsigned */
	}

	while (*nptr) {
		int n = 0;
		/* int c = iswide ? wctomb(*nptr) : *nptr; */

		switch (*nptr) {
		case '0': n = 0; break;
		case '1': n = 1; break;
		case '2': n = 2; break;
		case '3': n = 3; break;
		case '4': n = 4; break;
		case '5': n = 5; break;
		case '6': n = 6; break;
		case '7': n = 7; break;
		case '8': n = 8; break;
		case '9': n = 9; break;
		case 'a': case 'A': n = 0xa; break;
		case 'b': case 'B': n = 0xb; break;
		case 'c': case 'C': n = 0xc; break;
		case 'd': case 'D': n = 0xd; break;
		case 'e': case 'E': n = 0xe; break;
		case 'f': case 'F': n = 0xf; break;
		default: n = -1; break;
		}

		if (n >= base || n < 0) {
			*endptr = (void*)nptr;
			break;
		}

		ret = (ret * base) + n;
		nptr++;
	}