1 // SPDX-License-Identifier: GPL-2.0
6 * Copyright (C) 1991, 1992 Linus Torvalds
9 #include <linux/ctype.h>
10 #include <linux/types.h>
11 #include <linux/string.h>
13 #ifndef __HAVE_ARCH_STRSTR
15 * strstr - Find the first substring in a %NUL terminated string
16 * @s1: The string to be searched
17 * @s2: The string to search for
19 char *strstr(const char *s1
, const char *s2
)
29 if (!memcmp(s1
, s2
, l2
))
37 #ifndef __HAVE_ARCH_STRNCMP
39 * strncmp - Compare two length-limited strings
42 * @count: The maximum number of bytes to compare
44 int strncmp(const char *cs
, const char *ct
, size_t count
)
52 return c1
< c2
? -1 : 1;
61 /* Works only for digits and letters, but small and fast */
62 #define TOLOWER(x) ((x) | 0x20)
64 static unsigned int simple_guess_base(const char *cp
)
67 if (TOLOWER(cp
[1]) == 'x' && isxdigit(cp
[2]))
77 * simple_strtoull - convert a string to an unsigned long long
78 * @cp: The start of the string
79 * @endp: A pointer to the end of the parsed string will be placed here
80 * @base: The number base to use
83 unsigned long long simple_strtoull(const char *cp
, char **endp
, unsigned int base
)
85 unsigned long long result
= 0;
88 base
= simple_guess_base(cp
);
90 if (base
== 16 && cp
[0] == '0' && TOLOWER(cp
[1]) == 'x')
93 while (isxdigit(*cp
)) {
96 value
= isdigit(*cp
) ? *cp
- '0' : TOLOWER(*cp
) - 'a' + 10;
99 result
= result
* base
+ value
;
108 long simple_strtol(const char *cp
, char **endp
, unsigned int base
)
111 return -simple_strtoull(cp
+ 1, endp
, base
);
113 return simple_strtoull(cp
, endp
, base
);