xref: /original-bsd/lib/libc/string/strstr.c (revision c3e32dec)
1 /*-
2  * Copyright (c) 1990, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Chris Torek.
7  *
8  * %sccs.include.redist.c%
9  */
10 
11 #if defined(LIBC_SCCS) && !defined(lint)
12 static char sccsid[] = "@(#)strstr.c	8.1 (Berkeley) 06/04/93";
13 #endif /* LIBC_SCCS and not lint */
14 
15 #include <sys/cdefs.h>
16 #include <string.h>
17 
18 /*
19  * Find the first occurrence of find in s.
20  */
21 char *
22 strstr(s, find)
23 	register const char *s, *find;
24 {
25 	register char c, sc;
26 	register size_t len;
27 
28 	if ((c = *find++) != 0) {
29 		len = strlen(find);
30 		do {
31 			do {
32 				if ((sc = *s++) == 0)
33 					return (NULL);
34 			} while (sc != c);
35 		} while (strncmp(s, find, len) != 0);
36 		s--;
37 	}
38 	return ((char *)s);
39 }
40