1187498Simp#include "config.h" 2187498Simp 3187498Simp#if HAVE_STRCASESTR 4187498Simp 5187498Simpint dummy; 6187498Simp 7187498Simp#else 8187498Simp 9187498Simp/* Id: compat_strcasestr.c,v 1.4 2014/12/11 09:19:32 schwarze Exp */ 10187498Simp/* NetBSD: strcasestr.c,v 1.3 2005/11/29 03:12:00 christos Exp */ 11187498Simp 12187498Simp/*- 13187498Simp * Copyright (c) 1990, 1993 14187498Simp * The Regents of the University of California. All rights reserved. 15187498Simp * 16187498Simp * This code is derived from software contributed to Berkeley by 17187498Simp * Chris Torek. 18187498Simp * 19187498Simp * Redistribution and use in source and binary forms, with or without 20187498Simp * modification, are permitted provided that the following conditions 21187498Simp * are met: 22187498Simp * 1. Redistributions of source code must retain the above copyright 23187498Simp * notice, this list of conditions and the following disclaimer. 24187498Simp * 2. Redistributions in binary form must reproduce the above copyright 25187498Simp * notice, this list of conditions and the following disclaimer in the 26187498Simp * documentation and/or other materials provided with the distribution. 27187498Simp * 3. Neither the name of the University nor the names of its contributors 28187498Simp * may be used to endorse or promote products derived from this software 29187498Simp * without specific prior written permission. 30187498Simp * 31187498Simp * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 32187498Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 33187498Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 34187498Simp * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 35187498Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36187498Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37187498Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38187498Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 39187498Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 40187498Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 41187498Simp * SUCH DAMAGE. 42187498Simp */ 43187498Simp 44187498Simp#include <sys/types.h> 45187498Simp#include <ctype.h> 46187498Simp#include <string.h> 47187498Simp 48187498Simp#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) 49187498Simp 50187498Simp/* 51187498Simp * Find the first occurrence of find in s, ignore case. 52187498Simp */ 53187498Simpchar * 54187498Simpstrcasestr(const char *s, const char *find) 55187498Simp{ 56187498Simp char c, sc; 57187498Simp size_t len; 58187498Simp 59187498Simp if ((c = *find++) != 0) { 60187498Simp c = tolower((unsigned char)c); 61187498Simp len = strlen(find); 62187498Simp do { 63187498Simp do { 64187498Simp if ((sc = *s++) == 0) 65187498Simp return (NULL); 66187498Simp } while ((char)tolower((unsigned char)sc) != c); 67187498Simp } while (strncasecmp(s, find, len) != 0); 68187498Simp s--; 69187498Simp } 70187498Simp return __UNCONST(s); 71187498Simp} 72187498Simp 73187498Simp#endif 74187498Simp