strcasestr.c revision 4642e01f
14642e01fSmrg/*-
24642e01fSmrg * Copyright (c) 1990, 1993
34642e01fSmrg *      The Regents of the University of California.  All rights reserved.
44642e01fSmrg *
54642e01fSmrg * This code is derived from software contributed to Berkeley by
64642e01fSmrg * Chris Torek.
74642e01fSmrg *
84642e01fSmrg * Redistribution and use in source and binary forms, with or without
94642e01fSmrg * modification, are permitted provided that the following conditions
104642e01fSmrg * are met:
114642e01fSmrg * 1. Redistributions of source code must retain the above copyright
124642e01fSmrg *    notice, this list of conditions and the following disclaimer.
134642e01fSmrg * 2. Redistributions in binary form must reproduce the above copyright
144642e01fSmrg *    notice, this list of conditions and the following disclaimer in the
154642e01fSmrg *    documentation and/or other materials provided with the distribution.
164642e01fSmrg * 4. Neither the name of the University nor the names of its contributors
174642e01fSmrg *    may be used to endorse or promote products derived from this software
184642e01fSmrg *    without specific prior written permission.
194642e01fSmrg *
204642e01fSmrg * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
214642e01fSmrg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
224642e01fSmrg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
234642e01fSmrg * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
244642e01fSmrg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
254642e01fSmrg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
264642e01fSmrg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
274642e01fSmrg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
284642e01fSmrg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
294642e01fSmrg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
304642e01fSmrg * SUCH DAMAGE.
314642e01fSmrg */
324642e01fSmrg
334642e01fSmrg#ifdef HAVE_DIX_CONFIG_H
344642e01fSmrg#include <dix-config.h>
354642e01fSmrg#endif
364642e01fSmrg
374642e01fSmrg#include <ctype.h>
384642e01fSmrg#include <string.h>
394642e01fSmrg#include "dix.h"
404642e01fSmrg
414642e01fSmrg/*
424642e01fSmrg * Find the first occurrence of find in s, ignore case.
434642e01fSmrg */
444642e01fSmrg#ifdef NEED_STRCASESTR
454642e01fSmrgchar *
464642e01fSmrgxstrcasestr(const char *s, const char *find)
474642e01fSmrg{
484642e01fSmrg        char c, sc;
494642e01fSmrg        size_t len;
504642e01fSmrg
514642e01fSmrg        if ((c = *find++) != 0) {
524642e01fSmrg                c = tolower((unsigned char)c);
534642e01fSmrg                len = strlen(find);
544642e01fSmrg                do {
554642e01fSmrg                        do {
564642e01fSmrg                                if ((sc = *s++) == 0)
574642e01fSmrg                                        return (NULL);
584642e01fSmrg                        } while ((char)tolower((unsigned char)sc) != c);
594642e01fSmrg                } while (strncasecmp(s, find, len) != 0);
604642e01fSmrg                s--;
614642e01fSmrg        }
624642e01fSmrg        return ((char *)s);
634642e01fSmrg}
644642e01fSmrg#endif
65