HEX
Server: Apache
System: Linux s198.coreserver.jp 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC 2025 x86_64
User: nagasaki (10062)
PHP: 7.1.33
Disabled: NONE
Upload Files
File: //usr/local/rvm/src/ruby-2.5.9/missing/strstr.c
/* public domain rewrite of strstr(3) */

#include "ruby/missing.h"

size_t strlen(const char*);

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;
}