100bf4279Sespie /* Simple implementation of strstr for systems without it.
200bf4279Sespie This function is in the public domain. */
300bf4279Sespie
400bf4279Sespie /*
500bf4279Sespie
69588ddcfSespie @deftypefn Supplemental char* strstr (const char *@var{string}, const char *@var{sub})
700bf4279Sespie
89588ddcfSespie This function searches for the substring @var{sub} in the string
99588ddcfSespie @var{string}, not including the terminating null characters. A pointer
109588ddcfSespie to the first occurrence of @var{sub} is returned, or @code{NULL} if the
119588ddcfSespie substring is absent. If @var{sub} points to a string with zero
129588ddcfSespie length, the function returns @var{string}.
1300bf4279Sespie
149588ddcfSespie @end deftypefn
1500bf4279Sespie
1600bf4279Sespie
1700bf4279Sespie */
1800bf4279Sespie
1900bf4279Sespie
2000bf4279Sespie /* FIXME: The above description is ANSI compiliant. This routine has not
2100bf4279Sespie been validated to comply with it. -fnf */
2200bf4279Sespie
23*150b7e42Smiod #include <stddef.h>
24*150b7e42Smiod
25*150b7e42Smiod extern char *strchr (const char *, int);
26*150b7e42Smiod extern int strncmp (const void *, const void *, size_t);
27*150b7e42Smiod extern size_t strlen (const char *);
28*150b7e42Smiod
2900bf4279Sespie char *
strstr(const char * s1,const char * s2)30*150b7e42Smiod strstr (const char *s1, const char *s2)
3100bf4279Sespie {
32*150b7e42Smiod const char *p = s1;
33*150b7e42Smiod const size_t len = strlen (s2);
3400bf4279Sespie
3500bf4279Sespie for (; (p = strchr (p, *s2)) != 0; p++)
3600bf4279Sespie {
3700bf4279Sespie if (strncmp (p, s2, len) == 0)
38*150b7e42Smiod return (char *)p;
3900bf4279Sespie }
4000bf4279Sespie return (0);
4100bf4279Sespie }
42