1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/ctype.h>
3 #include <linux/kernel.h>
4 #include <linux/errno.h>
6 #include "../lib/string.c"
8 int strncmp(const char *cs
, const char *ct
, size_t count
)
16 return c1
< c2
? -1 : 1;
24 char *skip_spaces(const char *str
)
41 while (end
>= s
&& isspace(*end
))
45 return skip_spaces(s
);
48 /* Works only for digits and letters, but small and fast */
49 #define TOLOWER(x) ((x) | 0x20)
51 static unsigned int simple_guess_base(const char *cp
)
54 if (TOLOWER(cp
[1]) == 'x' && isxdigit(cp
[2]))
64 * simple_strtoull - convert a string to an unsigned long long
65 * @cp: The start of the string
66 * @endp: A pointer to the end of the parsed string will be placed here
67 * @base: The number base to use
70 unsigned long long simple_strtoull(const char *cp
, char **endp
,
73 unsigned long long result
= 0;
76 base
= simple_guess_base(cp
);
78 if (base
== 16 && cp
[0] == '0' && TOLOWER(cp
[1]) == 'x')
81 while (isxdigit(*cp
)) {
84 value
= isdigit(*cp
) ? *cp
- '0' : TOLOWER(*cp
) - 'a' + 10;
87 result
= result
* base
+ value
;
96 long simple_strtol(const char *cp
, char **endp
, unsigned int base
)
99 return -simple_strtoull(cp
+ 1, endp
, base
);
101 return simple_strtoull(cp
, endp
, base
);
104 int kstrtobool(const char *s
, bool *res
)