1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/ctype.h>
3 #include <linux/kernel.h>
4 #include <linux/errno.h>
6 #undef CONFIG_KASAN_GENERIC
7 #include "../lib/string.c"
9 int strncmp(const char *cs
, const char *ct
, size_t count
)
17 return c1
< c2
? -1 : 1;
25 char *skip_spaces(const char *str
)
42 while (end
>= s
&& isspace(*end
))
46 return skip_spaces(s
);
49 /* Works only for digits and letters, but small and fast */
50 #define TOLOWER(x) ((x) | 0x20)
52 static unsigned int simple_guess_base(const char *cp
)
55 if (TOLOWER(cp
[1]) == 'x' && isxdigit(cp
[2]))
65 * simple_strtoull - convert a string to an unsigned long long
66 * @cp: The start of the string
67 * @endp: A pointer to the end of the parsed string will be placed here
68 * @base: The number base to use
71 unsigned long long simple_strtoull(const char *cp
, char **endp
,
74 unsigned long long result
= 0;
77 base
= simple_guess_base(cp
);
79 if (base
== 16 && cp
[0] == '0' && TOLOWER(cp
[1]) == 'x')
82 while (isxdigit(*cp
)) {
85 value
= isdigit(*cp
) ? *cp
- '0' : TOLOWER(*cp
) - 'a' + 10;
88 result
= result
* base
+ value
;
97 long simple_strtol(const char *cp
, char **endp
, unsigned int base
)
100 return -simple_strtoull(cp
+ 1, endp
, base
);
102 return simple_strtoull(cp
, endp
, base
);
105 int kstrtobool(const char *s
, bool *res
)