Commit | Line | Data |
---|---|---|
80aa332f KB |
1 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | |
3 | * 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) | |
a64329b4 | 12 | static char sccsid[] = "@(#)strstr.c 5.2 (Berkeley) %G%"; |
80aa332f KB |
13 | #endif /* LIBC_SCCS and not lint */ |
14 | ||
a64329b4 | 15 | #include <sys/cdefs.h> |
80aa332f | 16 | #include <string.h> |
80aa332f KB |
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 | } |