Deleted Added
full compact
strnstr.c (165903) strnstr.c (188080)
1/*-
2 * Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
3 * Copyright (c) 1990, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Chris Torek.
8 *

--- 21 unchanged lines hidden (view full) ---

30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#if defined(LIBC_SCCS) && !defined(lint)
35static char sccsid[] = "@(#)strstr.c 8.1 (Berkeley) 6/4/93";
36#endif /* LIBC_SCCS and not lint */
37#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
3 * Copyright (c) 1990, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Chris Torek.
8 *

--- 21 unchanged lines hidden (view full) ---

30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#if defined(LIBC_SCCS) && !defined(lint)
35static char sccsid[] = "@(#)strstr.c 8.1 (Berkeley) 6/4/93";
36#endif /* LIBC_SCCS and not lint */
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD: head/lib/libc/string/strnstr.c 165903 2007-01-09 00:28:16Z imp $");
38__FBSDID("$FreeBSD: head/lib/libc/string/strnstr.c 188080 2009-02-03 17:58:20Z danger $");
39
40#include <string.h>
41
42/*
43 * Find the first occurrence of find in s, where the search is limited to the
44 * first slen characters of s.
45 */
46char *
39
40#include <string.h>
41
42/*
43 * Find the first occurrence of find in s, where the search is limited to the
44 * first slen characters of s.
45 */
46char *
47strnstr(s, find, slen)
48 const char *s;
49 const char *find;
50 size_t slen;
47strnstr(const char *s, const char *find, size_t slen)
51{
52 char c, sc;
53 size_t len;
54
55 if ((c = *find++) != '\0') {
56 len = strlen(find);
57 do {
58 do {
59 if (slen-- < 1 || (sc = *s++) == '\0')
60 return (NULL);
61 } while (sc != c);
62 if (len > slen)
63 return (NULL);
64 } while (strncmp(s, find, len) != 0);
65 s--;
66 }
67 return ((char *)s);
68}
48{
49 char c, sc;
50 size_t len;
51
52 if ((c = *find++) != '\0') {
53 len = strlen(find);
54 do {
55 do {
56 if (slen-- < 1 || (sc = *s++) == '\0')
57 return (NULL);
58 } while (sc != c);
59 if (len > slen)
60 return (NULL);
61 } while (strncmp(s, find, len) != 0);
62 s--;
63 }
64 return ((char *)s);
65}