]> git.ipfire.org Git - thirdparty/gcc.git/blame - libiberty/strstr.c
gcov: rename 2 options.
[thirdparty/gcc.git] / libiberty / strstr.c
CommitLineData
6599da04
JM
1/* Simple implementation of strstr for systems without it.
2 This function is in the public domain. */
3
4/*
5
aaa5f039 6@deftypefn Supplemental char* strstr (const char *@var{string}, const char *@var{sub})
6599da04 7
aaa5f039 8This function searches for the substring @var{sub} in the string
e922f978 9@var{string}, not including the terminating null characters. A pointer
7f8fa05d 10to the first occurrence of @var{sub} is returned, or @code{NULL} if the
aaa5f039
DD
11substring is absent. If @var{sub} points to a string with zero
12length, the function returns @var{string}.
6599da04 13
aaa5f039 14@end deftypefn
6599da04 15
6599da04
JM
16
17*/
18
19
20/* FIXME: The above description is ANSI compiliant. This routine has not
21 been validated to comply with it. -fnf */
22
f9a9ac80
KG
23#include <stddef.h>
24
25extern char *strchr (const char *, int);
26extern int strncmp (const void *, const void *, size_t);
27extern size_t strlen (const char *);
28
6599da04 29char *
f9a9ac80 30strstr (const char *s1, const char *s2)
6599da04 31{
f9a9ac80
KG
32 const char *p = s1;
33 const size_t len = strlen (s2);
6599da04
JM
34
35 for (; (p = strchr (p, *s2)) != 0; p++)
36 {
37 if (strncmp (p, s2, len) == 0)
f9a9ac80 38 return (char *)p;
6599da04
JM
39 }
40 return (0);
41}