Daily bump.
[official-gcc.git] / libiberty / strstr.c
blobc6f68495a33d124cec901251812150c52e2d0ea3
1 /* Simple implementation of strstr for systems without it.
2 This function is in the public domain. */
4 /*
6 @deftypefn Supplemental char* strstr (const char *@var{string}, const char *@var{sub})
8 This function searches for the substring @var{sub} in the string
9 @var{string}, not including the terminating null characters. A pointer
10 to the first occurrence of @var{sub} is returned, or @code{NULL} if the
11 substring is absent. If @var{sub} points to a string with zero
12 length, the function returns @var{string}.
14 @end deftypefn
19 #include <stddef.h>
21 extern int memcmp (const void *, const void *, size_t);
22 extern size_t strlen (const char *);
24 char *
25 strstr (const char *s1, const char *s2)
27 const size_t len = strlen (s2);
28 while (*s1)
30 if (!memcmp (s1, s2, len))
31 return (char *)s1;
32 ++s1;
34 return (0);