1313012Sdes/* $OpenBSD: strcasestr.c,v 1.4 2015/08/31 02:53:57 guenther Exp $ */ 2313012Sdes/* $NetBSD: strcasestr.c,v 1.2 2005/02/09 21:35:47 kleink Exp $ */ 3313012Sdes 4313012Sdes/*- 5313012Sdes * Copyright (c) 1990, 1993 6313012Sdes * The Regents of the University of California. All rights reserved. 7313012Sdes * 8313012Sdes * This code is derived from software contributed to Berkeley by 9313012Sdes * Chris Torek. 10313012Sdes * 11313012Sdes * Redistribution and use in source and binary forms, with or without 12313012Sdes * modification, are permitted provided that the following conditions 13313012Sdes * are met: 14313012Sdes * 1. Redistributions of source code must retain the above copyright 15313012Sdes * notice, this list of conditions and the following disclaimer. 16313012Sdes * 2. Redistributions in binary form must reproduce the above copyright 17313012Sdes * notice, this list of conditions and the following disclaimer in the 18313012Sdes * documentation and/or other materials provided with the distribution. 19313012Sdes * 3. Neither the name of the University nor the names of its contributors 20313012Sdes * may be used to endorse or promote products derived from this software 21313012Sdes * without specific prior written permission. 22313012Sdes * 23313012Sdes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24313012Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25313012Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26313012Sdes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27313012Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28313012Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29313012Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30313012Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31313012Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32313012Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33313012Sdes * SUCH DAMAGE. 34313012Sdes */ 35313012Sdes 36313012Sdes/* OPENBSD ORIGINAL: lib/libc/string/strcasestr.c */ 37313012Sdes 38313012Sdes#include "includes.h" 39313012Sdes 40313012Sdes#ifndef HAVE_STRCASESTR 41313012Sdes 42313012Sdes#include <ctype.h> 43313012Sdes#include <string.h> 44313012Sdes 45313012Sdes/* 46313012Sdes * Find the first occurrence of find in s, ignore case. 47313012Sdes */ 48313012Sdeschar * 49313012Sdesstrcasestr(const char *s, const char *find) 50313012Sdes{ 51313012Sdes char c, sc; 52313012Sdes size_t len; 53313012Sdes 54313012Sdes if ((c = *find++) != 0) { 55313012Sdes c = (char)tolower((unsigned char)c); 56313012Sdes len = strlen(find); 57313012Sdes do { 58313012Sdes do { 59313012Sdes if ((sc = *s++) == 0) 60313012Sdes return (NULL); 61313012Sdes } while ((char)tolower((unsigned char)sc) != c); 62313012Sdes } while (strncasecmp(s, find, len) != 0); 63313012Sdes s--; 64313012Sdes } 65313012Sdes return ((char *)s); 66313012Sdes} 67313012SdesDEF_WEAK(strcasestr); 68313012Sdes 69313012Sdes#endif 70