1 // SPDX-License-Identifier: GPL-2.0
6 * Copyright (C) 1991, 1992 Linus Torvalds
9 #include <linux/ctype.h>
10 #include <linux/kernel.h>
11 #include <linux/types.h>
12 #include <linux/string.h>
14 #ifndef __HAVE_ARCH_STRSTR
16 * strstr - Find the first substring in a %NUL terminated string
17 * @s1: The string to be searched
18 * @s2: The string to search for
20 char *strstr(const char *s1, const char *s2)
30 if (!memcmp(s1, s2, l2))
38 #ifndef __HAVE_ARCH_STRNCMP
40 * strncmp - Compare two length-limited strings
43 * @count: The maximum number of bytes to compare
45 int strncmp(const char *cs, const char *ct, size_t count)
53 return c1 < c2 ? -1 : 1;
62 /* Works only for digits and letters, but small and fast */
63 #define TOLOWER(x) ((x) | 0x20)
65 static unsigned int simple_guess_base(const char *cp)
68 if (TOLOWER(cp[1]) == 'x' && isxdigit(cp[2]))
78 * simple_strtoull - convert a string to an unsigned long long
79 * @cp: The start of the string
80 * @endp: A pointer to the end of the parsed string will be placed here
81 * @base: The number base to use
84 unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base)
86 unsigned long long result = 0;
89 base = simple_guess_base(cp);
91 if (base == 16 && cp[0] == '0' && TOLOWER(cp[1]) == 'x')
94 while (isxdigit(*cp)) {
97 value = isdigit(*cp) ? *cp - '0' : TOLOWER(*cp) - 'a' + 10;
100 result = result * base + value;
109 long simple_strtol(const char *cp, char **endp, unsigned int base)
112 return -simple_strtoull(cp + 1, endp, base);
114 return simple_strtoull(cp, endp, base);