1169695Skan/* Simple implementation of strstr for systems without it.
2169695Skan   This function is in the public domain.  */
3169695Skan
4169695Skan/*
5169695Skan
6169695Skan@deftypefn Supplemental char* strstr (const char *@var{string}, const char *@var{sub})
7169695Skan
8169695SkanThis function searches for the substring @var{sub} in the string
9169695Skan@var{string}, not including the terminating null characters.  A pointer
10169695Skanto the first occurrence of @var{sub} is returned, or @code{NULL} if the
11169695Skansubstring is absent.  If @var{sub} points to a string with zero
12169695Skanlength, the function returns @var{string}.
13169695Skan
14169695Skan@end deftypefn
15169695Skan
16169695Skan
17169695Skan*/
18169695Skan
19169695Skan
20169695Skan/* FIXME:  The above description is ANSI compiliant.  This routine has not
21169695Skan   been validated to comply with it.  -fnf */
22169695Skan
23169695Skan#include <stddef.h>
24169695Skan
25169695Skanextern char *strchr (const char *, int);
26169695Skanextern int strncmp (const void *, const void *, size_t);
27169695Skanextern size_t strlen (const char *);
28169695Skan
29169695Skanchar *
30169695Skanstrstr (const char *s1, const char *s2)
31169695Skan{
32169695Skan  const char *p = s1;
33169695Skan  const size_t len = strlen (s2);
34169695Skan
35169695Skan  for (; (p = strchr (p, *s2)) != 0; p++)
36169695Skan    {
37169695Skan      if (strncmp (p, s2, len) == 0)
38169695Skan	return (char *)p;
39169695Skan    }
40169695Skan  return (0);
41169695Skan}
42