1
2
3
4
5
6
7
8#include <linux/types.h>
9#include <linux/string.h>
10
11#ifndef __HAVE_ARCH_STRSTR
12
13
14
15
16
17char *strstr(const char *s1, const char *s2)
18{
19 size_t l1, l2;
20
21 l2 = strlen(s2);
22 if (!l2)
23 return (char *)s1;
24 l1 = strlen(s1);
25 while (l1 >= l2) {
26 l1--;
27 if (!memcmp(s1, s2, l2))
28 return (char *)s1;
29 s1++;
30 }
31 return NULL;
32}
33#endif
34
35#ifndef __HAVE_ARCH_STRNCMP
36
37
38
39
40
41
42int strncmp(const char *cs, const char *ct, size_t count)
43{
44 unsigned char c1, c2;
45
46 while (count) {
47 c1 = *cs++;
48 c2 = *ct++;
49 if (c1 != c2)
50 return c1 < c2 ? -1 : 1;
51 if (!c1)
52 break;
53 count--;
54 }
55 return 0;
56}
57#endif
58