192cf602eSVladimir Kondratyev /*-
292cf602eSVladimir Kondratyev * SPDX-License-Identifier: BSD-3-Clause
392cf602eSVladimir Kondratyev *
492cf602eSVladimir Kondratyev * Copyright (c) 1990, 1993
592cf602eSVladimir Kondratyev * The Regents of the University of California. All rights reserved.
692cf602eSVladimir Kondratyev *
792cf602eSVladimir Kondratyev * This code is derived from software contributed to Berkeley by
892cf602eSVladimir Kondratyev * Chris Torek.
992cf602eSVladimir Kondratyev *
1092cf602eSVladimir Kondratyev * Copyright (c) 2011 The FreeBSD Foundation
1192cf602eSVladimir Kondratyev * All rights reserved.
1292cf602eSVladimir Kondratyev * Portions of this software were developed by David Chisnall
1392cf602eSVladimir Kondratyev * under sponsorship from the FreeBSD Foundation.
1492cf602eSVladimir Kondratyev *
1592cf602eSVladimir Kondratyev * Redistribution and use in source and binary forms, with or without
1692cf602eSVladimir Kondratyev * modification, are permitted provided that the following conditions
1792cf602eSVladimir Kondratyev * are met:
1892cf602eSVladimir Kondratyev * 1. Redistributions of source code must retain the above copyright
1992cf602eSVladimir Kondratyev * notice, this list of conditions and the following disclaimer.
2092cf602eSVladimir Kondratyev * 2. Redistributions in binary form must reproduce the above copyright
2192cf602eSVladimir Kondratyev * notice, this list of conditions and the following disclaimer in the
2292cf602eSVladimir Kondratyev * documentation and/or other materials provided with the distribution.
2392cf602eSVladimir Kondratyev * 3. Neither the name of the University nor the names of its contributors
2492cf602eSVladimir Kondratyev * may be used to endorse or promote products derived from this software
2592cf602eSVladimir Kondratyev * without specific prior written permission.
2692cf602eSVladimir Kondratyev *
2792cf602eSVladimir Kondratyev * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2892cf602eSVladimir Kondratyev * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2992cf602eSVladimir Kondratyev * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3092cf602eSVladimir Kondratyev * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3192cf602eSVladimir Kondratyev * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3292cf602eSVladimir Kondratyev * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3392cf602eSVladimir Kondratyev * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3492cf602eSVladimir Kondratyev * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3592cf602eSVladimir Kondratyev * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3692cf602eSVladimir Kondratyev * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3792cf602eSVladimir Kondratyev * SUCH DAMAGE.
3892cf602eSVladimir Kondratyev */
3992cf602eSVladimir Kondratyev
40*bc861033SVladimir Kondratyev #include <sys/param.h>
41*bc861033SVladimir Kondratyev #include <sys/ctype.h>
42*bc861033SVladimir Kondratyev #include <sys/libkern.h>
4392cf602eSVladimir Kondratyev
4492cf602eSVladimir Kondratyev /*
4592cf602eSVladimir Kondratyev * Find the first occurrence of find in s, ignore case.
4692cf602eSVladimir Kondratyev */
4792cf602eSVladimir Kondratyev char *
strcasestr(const char * s,const char * find)48*bc861033SVladimir Kondratyev strcasestr(const char *s, const char *find)
4992cf602eSVladimir Kondratyev {
5092cf602eSVladimir Kondratyev char c, sc;
5192cf602eSVladimir Kondratyev size_t len;
5292cf602eSVladimir Kondratyev
5392cf602eSVladimir Kondratyev if ((c = *find++) != 0) {
54*bc861033SVladimir Kondratyev c = tolower((unsigned char)c);
5592cf602eSVladimir Kondratyev len = strlen(find);
5692cf602eSVladimir Kondratyev do {
5792cf602eSVladimir Kondratyev do {
5892cf602eSVladimir Kondratyev if ((sc = *s++) == 0)
5992cf602eSVladimir Kondratyev return (NULL);
60*bc861033SVladimir Kondratyev } while ((char)tolower((unsigned char)sc) != c);
61*bc861033SVladimir Kondratyev } while (strncasecmp(s, find, len) != 0);
6292cf602eSVladimir Kondratyev s--;
6392cf602eSVladimir Kondratyev }
64*bc861033SVladimir Kondratyev return (__DECONST(char *, s));
6592cf602eSVladimir Kondratyev }
66