1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/ctype.h>
3 #include <linux/kernel.h>
4 #include <linux/errno.h>
5 #include "../lib/string.c"
7 int strncmp(const char *cs, const char *ct, size_t count)
15 return c1 < c2 ? -1 : 1;
23 char *skip_spaces(const char *str)
40 while (end >= s && isspace(*end))
44 return skip_spaces(s);
47 /* Works only for digits and letters, but small and fast */
48 #define TOLOWER(x) ((x) | 0x20)
50 static unsigned int simple_guess_base(const char *cp)
53 if (TOLOWER(cp[1]) == 'x' && isxdigit(cp[2]))
63 * simple_strtoull - convert a string to an unsigned long long
64 * @cp: The start of the string
65 * @endp: A pointer to the end of the parsed string will be placed here
66 * @base: The number base to use
69 unsigned long long simple_strtoull(const char *cp, char **endp,
72 unsigned long long result = 0;
75 base = simple_guess_base(cp);
77 if (base == 16 && cp[0] == '0' && TOLOWER(cp[1]) == 'x')
80 while (isxdigit(*cp)) {
83 value = isdigit(*cp) ? *cp - '0' : TOLOWER(*cp) - 'a' + 10;
86 result = result * base + value;
95 long simple_strtol(const char *cp, char **endp, unsigned int base)
98 return -simple_strtoull(cp + 1, endp, base);
100 return simple_strtoull(cp, endp, base);
103 int kstrtobool(const char *s, bool *res)