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