1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Taken from:
4  *  linux/lib/string.c
5  *
6  *  Copyright (C) 1991, 1992  Linus Torvalds
7  */
8 
9 #include <linux/types.h>
10 #include <linux/string.h>
11 
12 #ifndef __HAVE_ARCH_STRSTR
13 /**
14  * strstr - Find the first substring in a %NUL terminated string
15  * @s1: The string to be searched
16  * @s2: The string to search for
17  */
18 char *strstr(const char *s1, const char *s2)
19 {
20 	size_t l1, l2;
21 
22 	l2 = strlen(s2);
23 	if (!l2)
24 		return (char *)s1;
25 	l1 = strlen(s1);
26 	while (l1 >= l2) {
27 		l1--;
28 		if (!memcmp(s1, s2, l2))
29 			return (char *)s1;
30 		s1++;
31 	}
32 	return NULL;
33 }
34 #endif
35 
36 #ifndef __HAVE_ARCH_STRNCMP
37 /**
38  * strncmp - Compare two length-limited strings
39  * @cs: One string
40  * @ct: Another string
41  * @count: The maximum number of bytes to compare
42  */
43 int strncmp(const char *cs, const char *ct, size_t count)
44 {
45 	unsigned char c1, c2;
46 
47 	while (count) {
48 		c1 = *cs++;
49 		c2 = *ct++;
50 		if (c1 != c2)
51 			return c1 < c2 ? -1 : 1;
52 		if (!c1)
53 			break;
54 		count--;
55 	}
56 	return 0;
57 }
58 #endif
59