[rubygems/rubygems] Use a constant empty tar header to avoid extra allocations
[ruby.git] / missing / strstr.c
blobe6613c5d2fb8fc3acf29a55f1460c37735e97d0f
1 /* public domain rewrite of strstr(3) */
3 #include "ruby/missing.h"
5 size_t strlen(const char*);
7 char *
8 strstr(const char *haystack, const char *needle)
10 const char *hend;
11 const char *a, *b;
13 if (*needle == 0) return (char *)haystack;
14 hend = haystack + strlen(haystack) - strlen(needle) + 1;
15 while (haystack < hend) {
16 if (*haystack == *needle) {
17 a = haystack;
18 b = needle;
19 for (;;) {
20 if (*b == 0) return (char *)haystack;
21 if (*a++ != *b++) {
22 break;
26 haystack++;
28 return 0;