2001-03-06 11:17:54 +03:00
|
|
|
/* public domain rewrite of strstr(3) */
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
char *
|
2005-10-20 06:22:50 +04:00
|
|
|
strstr(const char *haystack, const char *needle)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2005-10-20 06:22:50 +04:00
|
|
|
const char *hend;
|
|
|
|
const char *a, *b;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2005-10-20 06:22:50 +04:00
|
|
|
if (*needle == 0) return (char *)haystack;
|
2001-03-06 11:17:54 +03:00
|
|
|
hend = haystack + strlen(haystack) - strlen(needle) + 1;
|
|
|
|
while (haystack < hend) {
|
|
|
|
if (*haystack == *needle) {
|
|
|
|
a = haystack;
|
|
|
|
b = needle;
|
|
|
|
for (;;) {
|
2005-10-20 06:22:50 +04:00
|
|
|
if (*b == 0) return (char *)haystack;
|
2001-03-06 11:17:54 +03:00
|
|
|
if (*a++ != *b++) {
|
|
|
|
break;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
2001-03-06 11:17:54 +03:00
|
|
|
haystack++;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2001-03-06 11:17:54 +03:00
|
|
|
return 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|