blob: 2e9c282fb1fe3673a09271d59ac68fa1967032e8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
/* public domain rewrite of strstr(3) */
char *
strstr(const char *haystack, const char *needle)
{
const char *hend;
const char *a, *b;
if (*needle == 0) return (char *)haystack;
hend = haystack + strlen(haystack) - strlen(needle) + 1;
while (haystack < hend) {
if (*haystack == *needle) {
a = haystack;
b = needle;
for (;;) {
if (*b == 0) return (char *)haystack;
if (*a++ != *b++) {
break;
}
}
}
haystack++;
}
return 0;
}
|