* io.c (rb_open_file): encoding in mode string was ignored if perm is
[ruby-svn.git] / missing / strstr.c
blob2e9c282fb1fe3673a09271d59ac68fa1967032e8
1 /* public domain rewrite of strstr(3) */
3 char *
4 strstr(const char *haystack, const char *needle)
6 const char *hend;
7 const char *a, *b;
9 if (*needle == 0) return (char *)haystack;
10 hend = haystack + strlen(haystack) - strlen(needle) + 1;
11 while (haystack < hend) {
12 if (*haystack == *needle) {
13 a = haystack;
14 b = needle;
15 for (;;) {
16 if (*b == 0) return (char *)haystack;
17 if (*a++ != *b++) {
18 break;
22 haystack++;
24 return 0;