133965Sjdp/* Simple implementation of strstr for systems without it. 233965Sjdp This function is in the public domain. */ 333965Sjdp 433965Sjdp/* 533965Sjdp 689857Sobrien@deftypefn Supplemental char* strstr (const char *@var{string}, const char *@var{sub}) 733965Sjdp 889857SobrienThis function searches for the substring @var{sub} in the string 989857Sobrien@var{string}, not including the terminating null characters. A pointer 1089857Sobriento the first occurrence of @var{sub} is returned, or @code{NULL} if the 1189857Sobriensubstring is absent. If @var{sub} points to a string with zero 1289857Sobrienlength, the function returns @var{string}. 1333965Sjdp 1489857Sobrien@end deftypefn 1533965Sjdp 1633965Sjdp 1733965Sjdp*/ 1833965Sjdp 1933965Sjdp 2033965Sjdp/* FIXME: The above description is ANSI compiliant. This routine has not 2133965Sjdp been validated to comply with it. -fnf */ 2233965Sjdp 23218822Sdim#include <stddef.h> 24218822Sdim 25218822Sdimextern char *strchr (const char *, int); 26218822Sdimextern int strncmp (const void *, const void *, size_t); 27218822Sdimextern size_t strlen (const char *); 28218822Sdim 2933965Sjdpchar * 30218822Sdimstrstr (const char *s1, const char *s2) 3133965Sjdp{ 32218822Sdim const char *p = s1; 33218822Sdim const size_t len = strlen (s2); 3433965Sjdp 3533965Sjdp for (; (p = strchr (p, *s2)) != 0; p++) 3633965Sjdp { 3733965Sjdp if (strncmp (p, s2, len) == 0) 38218822Sdim return (char *)p; 3933965Sjdp } 4033965Sjdp return (0); 4133965Sjdp} 42