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 char * 00024 strstr (s1, s2) 00025 char *s1, *s2; 00026 { 00027 register char *p = s1; 00028 extern char *strchr (); 00029 extern int strncmp (); 00030 #if __GNUC__ >= 2 00031 extern __SIZE_TYPE__ strlen (const char *); 00032 #endif 00033 register int len = strlen (s2); 00034 00035 for (; (p = strchr (p, *s2)) != 0; p++) 00036 { 00037 if (strncmp (p, s2, len) == 0) 00038 { 00039 return (p); 00040 } 00041 } 00042 return (0); 00043 }
1.5.6