xref: /csrg-svn/lib/libc/string/strstr.c (revision 61193)
141984Sbostic /*-
2*61193Sbostic  * Copyright (c) 1990, 1993
3*61193Sbostic  *	The Regents of the University of California.  All rights reserved.
441984Sbostic  *
541984Sbostic  * This code is derived from software contributed to Berkeley by
641984Sbostic  * Chris Torek.
741984Sbostic  *
841984Sbostic  * %sccs.include.redist.c%
941984Sbostic  */
1041984Sbostic 
1141984Sbostic #if defined(LIBC_SCCS) && !defined(lint)
12*61193Sbostic static char sccsid[] = "@(#)strstr.c	8.1 (Berkeley) 06/04/93";
1341984Sbostic #endif /* LIBC_SCCS and not lint */
1441984Sbostic 
1546144Sbostic #include <sys/cdefs.h>
1641984Sbostic #include <string.h>
1741984Sbostic 
1841984Sbostic /*
1941984Sbostic  * Find the first occurrence of find in s.
2041984Sbostic  */
2141984Sbostic char *
strstr(s,find)2241984Sbostic strstr(s, find)
2341984Sbostic 	register const char *s, *find;
2441984Sbostic {
2541984Sbostic 	register char c, sc;
2641984Sbostic 	register size_t len;
2741984Sbostic 
2841984Sbostic 	if ((c = *find++) != 0) {
2941984Sbostic 		len = strlen(find);
3041984Sbostic 		do {
3141984Sbostic 			do {
3241984Sbostic 				if ((sc = *s++) == 0)
3341984Sbostic 					return (NULL);
3441984Sbostic 			} while (sc != c);
3541984Sbostic 		} while (strncmp(s, find, len) != 0);
3641984Sbostic 		s--;
3741984Sbostic 	}
3841984Sbostic 	return ((char *)s);
3941984Sbostic }
40