#ifndef HAVE_STRSTR /* From GNU libc. */ /* Return the first ocurrence of NEEDLE in HAYSTACK. */ char * strstr(const char *const haystack, const char *const needle) { register const char *const needle_end = strchr(needle, '\0'); register const char *const haystack_end = strchr(haystack, '\0'); register const size_t needle_len = needle_end - needle; register const size_t needle_last = needle_len - 1; register const char *begin; if (needle_len == 0) return (char *) haystack; /* ANSI 4.11.5.7, line 25. */ if ((size_t) (haystack_end - haystack) < needle_len) return NULL; for (begin = &haystack[needle_last]; begin < haystack_end; ++begin) { register const char *n = &needle[needle_last]; register const char *h = begin; do if (*h != *n) goto loop; /* continue for loop */ while (--n >= needle && --h >= haystack); return (char *) h; loop:; } return NULL; } #endif /* HAVE_STRSTR */