2001-03-06 03:17:54 -05:00
|
|
|
/* public domain rewrite of strstr(3) */
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2010-07-28 04:12:01 -04:00
|
|
|
#include "ruby/missing.h"
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
char *
|
2005-10-19 22:22:50 -04:00
|
|
|
strstr(const char *haystack, const char *needle)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2005-10-19 22:22:50 -04:00
|
|
|
const char *hend;
|
|
|
|
const char *a, *b;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2005-10-19 22:22:50 -04:00
|
|
|
if (*needle == 0) return (char *)haystack;
|
2001-03-06 03:17:54 -05:00
|
|
|
hend = haystack + strlen(haystack) - strlen(needle) + 1;
|
|
|
|
while (haystack < hend) {
|
|
|
|
if (*haystack == *needle) {
|
|
|
|
a = haystack;
|
|
|
|
b = needle;
|
|
|
|
for (;;) {
|
2005-10-19 22:22:50 -04:00
|
|
|
if (*b == 0) return (char *)haystack;
|
2001-03-06 03:17:54 -05:00
|
|
|
if (*a++ != *b++) {
|
|
|
|
break;
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
2001-03-06 03:17:54 -05:00
|
|
|
haystack++;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2001-03-06 03:17:54 -05:00
|
|
|
return 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|