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