diff --git a/src/system/libroot/posix/string/strstr.c b/src/system/libroot/posix/string/strstr.c index 44871f461d..3f8c9e532f 100644 --- a/src/system/libroot/posix/string/strstr.c +++ b/src/system/libroot/posix/string/strstr.c @@ -1,26 +1,23 @@ /* -** Copyright 2001, Travis Geiselbrecht. All rights reserved. -** Distributed under the terms of the NewOS License. -*/ + * Taken from Wikipedia, which declared it as "public domain". + */ #include #include char * -strstr(char const *s1, char const *s2) +strstr(const char *s1, const char *s2) { - int l1, l2; - - l2 = strlen(s2); - if (!l2) - return (char *)s1; - l1 = strlen(s1); - while (l1 >= l2) { - l1--; - if (!memcmp(s1,s2,l2)) - return (char *)s1; - s1++; - } - return NULL; + size_t s2len; + /* Check for the null s2 case. */ + if (*s2 == '\0') + return (char *) s1; + s2len = strlen(s2); + for (; (s1 = strchr(s1, *s2)) != NULL; s1++) { + if (strncmp(s1, s2, s2len) == 0) + return (char *)s1; + } + return NULL; } +