00001 /* Simple implementation of strstr for systems without it. 00002 This function is in the public domain. */ 00003 00004 /* 00005 00006 @deftypefn Supplemental char* strstr (const char *@var{string}, const char *@var{sub}) 00007 00008 This function searches for the substring @var{sub} in the string 00009 @var{string}, not including the terminating null characters. A pointer 00010 to the first occurrence of @var{sub} is returned, or @code{NULL} if the 00011 substring is absent. If @var{sub} points to a string with zero 00012 length, the function returns @var{string}. 00013 00014 @end deftypefn 00015 00016 00017 */ 00018 00019 00020 /* FIXME: The above description is ANSI compiliant. This routine has not 00021 been validated to comply with it. -fnf */ 00022 00023 #include <stddef.h> 00024 00025 extern char *strchr (const char *, int); 00026 extern int strncmp (const void *, const void *, size_t); 00027 extern size_t strlen (const char *); 00028 00029 char * 00030 strstr (const char *s1, const char *s2) 00031 { 00032 const char *p = s1; 00033 const size_t len = strlen (s2); 00034 00035 for (; (p = strchr (p, *s2)) != 0; p++) 00036 { 00037 if (strncmp (p, s2, len) == 0) 00038 return (char *)p; 00039 } 00040 return (0); 00041 }
1.5.6