170f041f9Sjoerg #include "config.h"
270f041f9Sjoerg
3fec65c98Schristos #if HAVE_STRCASESTR
470f041f9Sjoerg
570f041f9Sjoerg int dummy;
670f041f9Sjoerg
770f041f9Sjoerg #else
870f041f9Sjoerg
9*9ff1f2acSchristos /* Id: compat_strcasestr.c,v 1.4 2014/12/11 09:19:32 schwarze Exp */
10*9ff1f2acSchristos /* NetBSD: strcasestr.c,v 1.3 2005/11/29 03:12:00 christos Exp */
1170f041f9Sjoerg
1270f041f9Sjoerg /*-
1370f041f9Sjoerg * Copyright (c) 1990, 1993
1470f041f9Sjoerg * The Regents of the University of California. All rights reserved.
1570f041f9Sjoerg *
1670f041f9Sjoerg * This code is derived from software contributed to Berkeley by
1770f041f9Sjoerg * Chris Torek.
1870f041f9Sjoerg *
1970f041f9Sjoerg * Redistribution and use in source and binary forms, with or without
2070f041f9Sjoerg * modification, are permitted provided that the following conditions
2170f041f9Sjoerg * are met:
2270f041f9Sjoerg * 1. Redistributions of source code must retain the above copyright
2370f041f9Sjoerg * notice, this list of conditions and the following disclaimer.
2470f041f9Sjoerg * 2. Redistributions in binary form must reproduce the above copyright
2570f041f9Sjoerg * notice, this list of conditions and the following disclaimer in the
2670f041f9Sjoerg * documentation and/or other materials provided with the distribution.
2770f041f9Sjoerg * 3. Neither the name of the University nor the names of its contributors
2870f041f9Sjoerg * may be used to endorse or promote products derived from this software
2970f041f9Sjoerg * without specific prior written permission.
3070f041f9Sjoerg *
3170f041f9Sjoerg * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
3270f041f9Sjoerg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3370f041f9Sjoerg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3470f041f9Sjoerg * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3570f041f9Sjoerg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3670f041f9Sjoerg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3770f041f9Sjoerg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3870f041f9Sjoerg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3970f041f9Sjoerg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
4070f041f9Sjoerg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
4170f041f9Sjoerg * SUCH DAMAGE.
4270f041f9Sjoerg */
4370f041f9Sjoerg
4470f041f9Sjoerg #include <sys/types.h>
4570f041f9Sjoerg #include <ctype.h>
4670f041f9Sjoerg #include <string.h>
4770f041f9Sjoerg
4870f041f9Sjoerg #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
4970f041f9Sjoerg
5070f041f9Sjoerg /*
5170f041f9Sjoerg * Find the first occurrence of find in s, ignore case.
5270f041f9Sjoerg */
5370f041f9Sjoerg char *
strcasestr(const char * s,const char * find)5470f041f9Sjoerg strcasestr(const char *s, const char *find)
5570f041f9Sjoerg {
5670f041f9Sjoerg char c, sc;
5770f041f9Sjoerg size_t len;
5870f041f9Sjoerg
5970f041f9Sjoerg if ((c = *find++) != 0) {
6070f041f9Sjoerg c = tolower((unsigned char)c);
6170f041f9Sjoerg len = strlen(find);
6270f041f9Sjoerg do {
6370f041f9Sjoerg do {
6470f041f9Sjoerg if ((sc = *s++) == 0)
6570f041f9Sjoerg return (NULL);
6670f041f9Sjoerg } while ((char)tolower((unsigned char)sc) != c);
6770f041f9Sjoerg } while (strncasecmp(s, find, len) != 0);
6870f041f9Sjoerg s--;
6970f041f9Sjoerg }
7070f041f9Sjoerg return __UNCONST(s);
7170f041f9Sjoerg }
7270f041f9Sjoerg
7370f041f9Sjoerg #endif
74