184740Sache/*- 284740Sache * Copyright (c) 1990, 1993 384740Sache * The Regents of the University of California. All rights reserved. 484740Sache * 584740Sache * This code is derived from software contributed to Berkeley by 684740Sache * Chris Torek. 784740Sache * 8227753Stheraven * Copyright (c) 2011 The FreeBSD Foundation 9227753Stheraven * All rights reserved. 10227753Stheraven * Portions of this software were developed by David Chisnall 11227753Stheraven * under sponsorship from the FreeBSD Foundation. 12227753Stheraven * 1384740Sache * Redistribution and use in source and binary forms, with or without 1484740Sache * modification, are permitted provided that the following conditions 1584740Sache * are met: 1684740Sache * 1. Redistributions of source code must retain the above copyright 1784740Sache * notice, this list of conditions and the following disclaimer. 1884740Sache * 2. Redistributions in binary form must reproduce the above copyright 1984740Sache * notice, this list of conditions and the following disclaimer in the 2084740Sache * documentation and/or other materials provided with the distribution. 21251069Semaste * 3. Neither the name of the University nor the names of its contributors 2284740Sache * may be used to endorse or promote products derived from this software 2384740Sache * without specific prior written permission. 2484740Sache * 2584740Sache * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2684740Sache * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2784740Sache * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2884740Sache * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2984740Sache * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3084740Sache * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3184740Sache * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3284740Sache * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3384740Sache * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3484740Sache * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3584740Sache * SUCH DAMAGE. 3684740Sache */ 3784740Sache 3886170Sobrien#include <sys/cdefs.h> 3986170Sobrien__FBSDID("$FreeBSD$"); 4084740Sache 4184740Sache#include <ctype.h> 4284740Sache#include <string.h> 43227753Stheraven#include "xlocale_private.h" 4484740Sache 4584740Sache/* 4684740Sache * Find the first occurrence of find in s, ignore case. 4784740Sache */ 4884740Sachechar * 49227753Stheravenstrcasestr_l(const char *s, const char *find, locale_t locale) 5084740Sache{ 5192889Sobrien char c, sc; 5292889Sobrien size_t len; 53227753Stheraven FIX_LOCALE(locale); 5484740Sache 5584740Sache if ((c = *find++) != 0) { 56227753Stheraven c = tolower_l((unsigned char)c, locale); 5784740Sache len = strlen(find); 5884740Sache do { 5984740Sache do { 6084740Sache if ((sc = *s++) == 0) 6184740Sache return (NULL); 62227753Stheraven } while ((char)tolower_l((unsigned char)sc, locale) != c); 63227753Stheraven } while (strncasecmp_l(s, find, len, locale) != 0); 6484740Sache s--; 6584740Sache } 6684740Sache return ((char *)s); 6784740Sache} 68227753Stheravenchar * 69227753Stheravenstrcasestr(const char *s, const char *find) 70227753Stheraven{ 71227753Stheraven return strcasestr_l(s, find, __get_locale()); 72227753Stheraven} 73