1 // SPDX-License-Identifier: GPL-2.0
2 #define IN_BOOT_STRING_C 1
3 #include <linux/ctype.h>
4 #include <linux/kernel.h>
5 #include <linux/errno.h>
7 #undef CONFIG_KASAN_GENERIC
9 #include "../lib/string.c"
12 * Duplicate some functions from the common lib/string.c
13 * instead of fully including it.
16 int strncmp(const char *cs, const char *ct, size_t count)
24 return c1 < c2 ? -1 : 1;
32 void *memset64(uint64_t *s, uint64_t v, size_t count)
41 char *skip_spaces(const char *str)
58 while (end >= s && isspace(*end))
62 return skip_spaces(s);
65 /* Works only for digits and letters, but small and fast */
66 #define TOLOWER(x) ((x) | 0x20)
68 static unsigned int simple_guess_base(const char *cp)
71 if (TOLOWER(cp[1]) == 'x' && isxdigit(cp[2]))
81 * simple_strtoull - convert a string to an unsigned long long
82 * @cp: The start of the string
83 * @endp: A pointer to the end of the parsed string will be placed here
84 * @base: The number base to use
87 unsigned long long simple_strtoull(const char *cp, char **endp,
90 unsigned long long result = 0;
93 base = simple_guess_base(cp);
95 if (base == 16 && cp[0] == '0' && TOLOWER(cp[1]) == 'x')
98 while (isxdigit(*cp)) {
101 value = isdigit(*cp) ? *cp - '0' : TOLOWER(*cp) - 'a' + 10;
104 result = result * base + value;
113 long simple_strtol(const char *cp, char **endp, unsigned int base)
116 return -simple_strtoull(cp + 1, endp, base);
118 return simple_strtoull(cp, endp, base);
121 int kstrtobool(const char *s, bool *res)