1274876Sbapt#include "config.h" 2274876Sbapt 3275432Sbapt#if HAVE_STRCASESTR 4274876Sbapt 5274876Sbaptint dummy; 6274876Sbapt 7274876Sbapt#else 8274876Sbapt 9276219Sbapt/* $Id: compat_strcasestr.c,v 1.4 2014/12/11 09:19:32 schwarze Exp $ */ 10276219Sbapt/* $NetBSD: strcasestr.c,v 1.3 2005/11/29 03:12:00 christos Exp $ */ 11274876Sbapt 12274876Sbapt/*- 13274876Sbapt * Copyright (c) 1990, 1993 14274876Sbapt * The Regents of the University of California. All rights reserved. 15274876Sbapt * 16274876Sbapt * This code is derived from software contributed to Berkeley by 17274876Sbapt * Chris Torek. 18274876Sbapt * 19274876Sbapt * Redistribution and use in source and binary forms, with or without 20274876Sbapt * modification, are permitted provided that the following conditions 21274876Sbapt * are met: 22274876Sbapt * 1. Redistributions of source code must retain the above copyright 23274876Sbapt * notice, this list of conditions and the following disclaimer. 24274876Sbapt * 2. Redistributions in binary form must reproduce the above copyright 25274876Sbapt * notice, this list of conditions and the following disclaimer in the 26274876Sbapt * documentation and/or other materials provided with the distribution. 27274876Sbapt * 3. Neither the name of the University nor the names of its contributors 28274876Sbapt * may be used to endorse or promote products derived from this software 29274876Sbapt * without specific prior written permission. 30274876Sbapt * 31274876Sbapt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 32274876Sbapt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 33274876Sbapt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 34274876Sbapt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 35274876Sbapt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36274876Sbapt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37274876Sbapt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38274876Sbapt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 39274876Sbapt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 40274876Sbapt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 41274876Sbapt * SUCH DAMAGE. 42274876Sbapt */ 43274876Sbapt 44274876Sbapt#include <sys/types.h> 45274876Sbapt#include <ctype.h> 46274876Sbapt#include <string.h> 47274876Sbapt 48274876Sbapt#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) 49274876Sbapt 50274876Sbapt/* 51274876Sbapt * Find the first occurrence of find in s, ignore case. 52274876Sbapt */ 53274876Sbaptchar * 54274876Sbaptstrcasestr(const char *s, const char *find) 55274876Sbapt{ 56274876Sbapt char c, sc; 57274876Sbapt size_t len; 58274876Sbapt 59274876Sbapt if ((c = *find++) != 0) { 60274876Sbapt c = tolower((unsigned char)c); 61274876Sbapt len = strlen(find); 62274876Sbapt do { 63274876Sbapt do { 64274876Sbapt if ((sc = *s++) == 0) 65274876Sbapt return (NULL); 66274876Sbapt } while ((char)tolower((unsigned char)sc) != c); 67274876Sbapt } while (strncasecmp(s, find, len) != 0); 68274876Sbapt s--; 69274876Sbapt } 70274876Sbapt return __UNCONST(s); 71274876Sbapt} 72274876Sbapt 73274876Sbapt#endif 74