184699Smike/*- 284699Smike * Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org> 384699Smike * Copyright (c) 1990, 1993 484699Smike * The Regents of the University of California. All rights reserved. 584699Smike * 684699Smike * This code is derived from software contributed to Berkeley by 784699Smike * Chris Torek. 884699Smike * 984699Smike * Redistribution and use in source and binary forms, with or without 1084699Smike * modification, are permitted provided that the following conditions 1184699Smike * are met: 1284699Smike * 1. Redistributions of source code must retain the above copyright 1384699Smike * notice, this list of conditions and the following disclaimer. 1484699Smike * 2. Redistributions in binary form must reproduce the above copyright 1584699Smike * notice, this list of conditions and the following disclaimer in the 1684699Smike * documentation and/or other materials provided with the distribution. 17251069Semaste * 3. Neither the name of the University nor the names of its contributors 1884699Smike * may be used to endorse or promote products derived from this software 1984699Smike * without specific prior written permission. 2084699Smike * 2184699Smike * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2284699Smike * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2384699Smike * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2484699Smike * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2584699Smike * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2684699Smike * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2784699Smike * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2884699Smike * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2984699Smike * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3084699Smike * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3184699Smike * SUCH DAMAGE. 3284699Smike */ 3384699Smike 3486170Sobrien#if defined(LIBC_SCCS) && !defined(lint) 3586170Sobrienstatic char sccsid[] = "@(#)strstr.c 8.1 (Berkeley) 6/4/93"; 3686170Sobrien#endif /* LIBC_SCCS and not lint */ 3784699Smike#include <sys/cdefs.h> 3884699Smike__FBSDID("$FreeBSD$"); 3984699Smike 4084699Smike#include <string.h> 4184699Smike 4284699Smike/* 4384699Smike * Find the first occurrence of find in s, where the search is limited to the 4484699Smike * first slen characters of s. 4584699Smike */ 4684699Smikechar * 47188080Sdangerstrnstr(const char *s, const char *find, size_t slen) 4884699Smike{ 4984699Smike char c, sc; 5084699Smike size_t len; 5184699Smike 5284699Smike if ((c = *find++) != '\0') { 5384699Smike len = strlen(find); 5484699Smike do { 5584699Smike do { 56141701Spjd if (slen-- < 1 || (sc = *s++) == '\0') 5784699Smike return (NULL); 5884699Smike } while (sc != c); 5984699Smike if (len > slen) 6084699Smike return (NULL); 6184699Smike } while (strncmp(s, find, len) != 0); 6284699Smike s--; 6384699Smike } 6484699Smike return ((char *)s); 6584699Smike} 66