strto.c (5ebd27d860ec0c6e36f1b0f973653fe66a7360be) strto.c (2e794614838292499910060509d3c4a7aaed986a)
1/*
2 * linux/lib/vsprintf.c
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 */
6
7/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */
8/*
9 * Wirzenius wrote this portably, Torvalds fucked it up :-)
10 */
11
12#include <common.h>
13#include <errno.h>
14#include <linux/ctype.h>
15
1/*
2 * linux/lib/vsprintf.c
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 */
6
7/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */
8/*
9 * Wirzenius wrote this portably, Torvalds fucked it up :-)
10 */
11
12#include <common.h>
13#include <errno.h>
14#include <linux/ctype.h>
15
16/* from lib/kstrtox.c */
17static const char *_parse_integer_fixup_radix(const char *s, unsigned int *base)
18{
19 if (*base == 0) {
20 if (s[0] == '0') {
21 if (tolower(s[1]) == 'x' && isxdigit(s[2]))
22 *base = 16;
23 else
24 *base = 8;
25 } else
26 *base = 10;
27 }
28 if (*base == 16 && s[0] == '0' && tolower(s[1]) == 'x')
29 s += 2;
30 return s;
31}
32
16unsigned long simple_strtoul(const char *cp, char **endp,
17 unsigned int base)
18{
19 unsigned long result = 0;
20 unsigned long value;
21
33unsigned long simple_strtoul(const char *cp, char **endp,
34 unsigned int base)
35{
36 unsigned long result = 0;
37 unsigned long value;
38
22 if (*cp == '0') {
23 cp++;
24 if ((*cp == 'x') && isxdigit(cp[1])) {
25 base = 16;
26 cp++;
27 }
39 cp = _parse_integer_fixup_radix(cp, &base);
28
40
29 if (!base)
30 base = 8;
31 }
32
33 if (!base)
34 base = 10;
35
36 while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp)
37 ? toupper(*cp) : *cp)-'A'+10) < base) {
38 result = result*base + value;
39 cp++;
40 }
41
42 if (endp)
43 *endp = (char *)cp;

--- 79 unchanged lines hidden (view full) ---

123 return result;
124}
125
126unsigned long long simple_strtoull(const char *cp, char **endp,
127 unsigned int base)
128{
129 unsigned long long result = 0, value;
130
41 while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp)
42 ? toupper(*cp) : *cp)-'A'+10) < base) {
43 result = result*base + value;
44 cp++;
45 }
46
47 if (endp)
48 *endp = (char *)cp;

--- 79 unchanged lines hidden (view full) ---

128 return result;
129}
130
131unsigned long long simple_strtoull(const char *cp, char **endp,
132 unsigned int base)
133{
134 unsigned long long result = 0, value;
135
131 if (*cp == '0') {
132 cp++;
133 if ((*cp == 'x') && isxdigit(cp[1])) {
134 base = 16;
135 cp++;
136 }
136 cp = _parse_integer_fixup_radix(cp, &base);
137
137
138 if (!base)
139 base = 8;
140 }
141
142 if (!base)
143 base = 10;
144
145 while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp - '0'
146 : (islower(*cp) ? toupper(*cp) : *cp) - 'A' + 10) < base) {
147 result = result * base + value;
148 cp++;
149 }
150
151 if (endp)
152 *endp = (char *) cp;

--- 24 unchanged lines hidden ---
138 while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp - '0'
139 : (islower(*cp) ? toupper(*cp) : *cp) - 'A' + 10) < base) {
140 result = result * base + value;
141 cp++;
142 }
143
144 if (endp)
145 *endp = (char *) cp;

--- 24 unchanged lines hidden ---