strcasestr.c revision 84740
11556Srgrimes/*- 21556Srgrimes * Copyright (c) 1990, 1993 31556Srgrimes * The Regents of the University of California. All rights reserved. 41556Srgrimes * 51556Srgrimes * This code is derived from software contributed to Berkeley by 61556Srgrimes * Chris Torek. 71556Srgrimes * 81556Srgrimes * Redistribution and use in source and binary forms, with or without 91556Srgrimes * modification, are permitted provided that the following conditions 101556Srgrimes * are met: 111556Srgrimes * 1. Redistributions of source code must retain the above copyright 121556Srgrimes * notice, this list of conditions and the following disclaimer. 131556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 141556Srgrimes * notice, this list of conditions and the following disclaimer in the 151556Srgrimes * documentation and/or other materials provided with the distribution. 161556Srgrimes * 3. All advertising materials mentioning features or use of this software 171556Srgrimes * must display the following acknowledgement: 181556Srgrimes * This product includes software developed by the University of 191556Srgrimes * California, Berkeley and its contributors. 201556Srgrimes * 4. Neither the name of the University nor the names of its contributors 211556Srgrimes * may be used to endorse or promote products derived from this software 221556Srgrimes * without specific prior written permission. 231556Srgrimes * 241556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 251556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 261556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 271556Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 281556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 291556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 301556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 311556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 323044Sdg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 333044Sdg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 341556Srgrimes * SUCH DAMAGE. 351556Srgrimes */ 361556Srgrimes 371556Srgrimes#ifndef lint 381556Srgrimesstatic const char rcsid[] = 391556Srgrimes "$FreeBSD: head/lib/libc/string/strcasestr.c 84740 2001-10-10 02:17:35Z ache $"; 401556Srgrimes#endif 411556Srgrimes 421556Srgrimes#include <sys/cdefs.h> 431556Srgrimes#include <ctype.h> 441556Srgrimes#include <string.h> 451556Srgrimes 461556Srgrimes/* 471556Srgrimes * Find the first occurrence of find in s, ignore case. 481556Srgrimes */ 491556Srgrimeschar * 501556Srgrimesstrcasestr(s, find) 511556Srgrimes register const char *s, *find; 521556Srgrimes{ 531556Srgrimes register char c, sc; 541556Srgrimes register size_t len; 551556Srgrimes 561556Srgrimes if ((c = *find++) != 0) { 571556Srgrimes c = tolower((unsigned char)c); 581556Srgrimes len = strlen(find); 591556Srgrimes do { 601556Srgrimes do { 611556Srgrimes if ((sc = *s++) == 0) 621556Srgrimes return (NULL); 631556Srgrimes } while ((char)tolower((unsigned char)sc) != c); 641556Srgrimes } while (strncasecmp(s, find, len) != 0); 651556Srgrimes s--; 661556Srgrimes } 671556Srgrimes return ((char *)s); 681556Srgrimes} 691556Srgrimes