4 * Copyright (C) 1991, 1992 Linus Torvalds
7 /* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */
9 * Wirzenius wrote this portably, Torvalds fucked it up :-)
14 #include <linux/ctype.h>
16 unsigned long simple_strtoul(const char *cp, char **endp,
19 unsigned long result = 0;
24 if ((*cp == 'x') && isxdigit(cp[1])) {
36 while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp)
37 ? toupper(*cp) : *cp)-'A'+10) < base) {
38 result = result*base + value;
48 int strict_strtoul(const char *cp, unsigned int base, unsigned long *res)
59 val = simple_strtoul(cp, &tail, base);
63 if ((*tail == '\0') ||
64 ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) {
72 long simple_strtol(const char *cp, char **endp, unsigned int base)
75 return -simple_strtoul(cp + 1, endp, base);
77 return simple_strtoul(cp, endp, base);
80 unsigned long ustrtoul(const char *cp, char **endp, unsigned int base)
82 unsigned long result = simple_strtoul(cp, endp, base);
93 if ((*endp)[1] == 'i') {
94 if ((*endp)[2] == 'B')
103 unsigned long long ustrtoull(const char *cp, char **endp, unsigned int base)
105 unsigned long long result = simple_strtoull(cp, endp, base);
116 if ((*endp)[1] == 'i') {
117 if ((*endp)[2] == 'B')
126 unsigned long long simple_strtoull(const char *cp, char **endp,
129 unsigned long long result = 0, value;
133 if ((*cp == 'x') && isxdigit(cp[1])) {
145 while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp - '0'
146 : (islower(*cp) ? toupper(*cp) : *cp) - 'A' + 10) < base) {
147 result = result * base + value;
157 long trailing_strtoln(const char *str, const char *end)
162 end = str + strlen(str);
163 for (p = end - 1; p > str; p--) {
165 return simple_strtoul(p + 1, NULL, 10);
171 long trailing_strtol(const char *str)
173 return trailing_strtoln(str, NULL);