1
2
3
4
5
6
7
8
9#include <linux/types.h>
10#include <linux/string.h>
11
12#ifndef __HAVE_ARCH_STRSTR
13
14
15
16
17
18char *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
39
40
41
42
43int 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