Fix fallout from PR middle-end/15700:
[official-gcc.git] / libiberty / strstr.c
blobff8abd20f786add836af29c309109533f0965aba
1 /* Simple implementation of strstr for systems without it.
2 This function is in the public domain. */
4 /*
6 @deftypefn Supplemental char* strstr (const char *@var{string}, const char *@var{sub})
8 This function searches for the substring @var{sub} in the string
9 @var{string}, not including the terminating null characters. A pointer
10 to the first occurrence of @var{sub} is returned, or @code{NULL} if the
11 substring is absent. If @var{sub} points to a string with zero
12 length, the function returns @var{string}.
14 @end deftypefn
20 /* FIXME: The above description is ANSI compiliant. This routine has not
21 been validated to comply with it. -fnf */
23 char *
24 strstr (char *s1, char *s2)
26 register char *p = s1;
27 extern char *strchr ();
28 extern int strncmp ();
29 #if __GNUC__ >= 2
30 extern __SIZE_TYPE__ strlen (const char *);
31 #endif
32 register int len = strlen (s2);
34 for (; (p = strchr (p, *s2)) != 0; p++)
36 if (strncmp (p, s2, len) == 0)
38 return (p);
41 return (0);