1*37c9f0a6Schristos /* $NetBSD: strcasecmp.c,v 1.1 2005/12/20 19:28:52 christos Exp $ */ 2*37c9f0a6Schristos 3*37c9f0a6Schristos /* 4*37c9f0a6Schristos * Copyright (c) 1987, 1993 5*37c9f0a6Schristos * The Regents of the University of California. All rights reserved. 6*37c9f0a6Schristos * 7*37c9f0a6Schristos * Redistribution and use in source and binary forms, with or without 8*37c9f0a6Schristos * modification, are permitted provided that the following conditions 9*37c9f0a6Schristos * are met: 10*37c9f0a6Schristos * 1. Redistributions of source code must retain the above copyright 11*37c9f0a6Schristos * notice, this list of conditions and the following disclaimer. 12*37c9f0a6Schristos * 2. Redistributions in binary form must reproduce the above copyright 13*37c9f0a6Schristos * notice, this list of conditions and the following disclaimer in the 14*37c9f0a6Schristos * documentation and/or other materials provided with the distribution. 15*37c9f0a6Schristos * 3. Neither the name of the University nor the names of its contributors 16*37c9f0a6Schristos * may be used to endorse or promote products derived from this software 17*37c9f0a6Schristos * without specific prior written permission. 18*37c9f0a6Schristos * 19*37c9f0a6Schristos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20*37c9f0a6Schristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21*37c9f0a6Schristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22*37c9f0a6Schristos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23*37c9f0a6Schristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24*37c9f0a6Schristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25*37c9f0a6Schristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26*37c9f0a6Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27*37c9f0a6Schristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28*37c9f0a6Schristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29*37c9f0a6Schristos * SUCH DAMAGE. 30*37c9f0a6Schristos */ 31*37c9f0a6Schristos 32*37c9f0a6Schristos #include <sys/cdefs.h> 33*37c9f0a6Schristos #if defined(LIBC_SCCS) && !defined(lint) 34*37c9f0a6Schristos #if 0 35*37c9f0a6Schristos static char sccsid[] = "@(#)strcasecmp.c 8.1 (Berkeley) 6/4/93"; 36*37c9f0a6Schristos #else 37*37c9f0a6Schristos __RCSID("$NetBSD: strcasecmp.c,v 1.1 2005/12/20 19:28:52 christos Exp $"); 38*37c9f0a6Schristos #endif 39*37c9f0a6Schristos #endif /* LIBC_SCCS and not lint */ 40*37c9f0a6Schristos 41*37c9f0a6Schristos #if !defined(_KERNEL) && !defined(_STANDALONE) 42*37c9f0a6Schristos #include "namespace.h" 43*37c9f0a6Schristos #include <assert.h> 44*37c9f0a6Schristos #include <ctype.h> 45*37c9f0a6Schristos #include <string.h> 46*37c9f0a6Schristos #ifdef __weak_alias 47*37c9f0a6Schristos __weak_alias(strcasecmp,_strcasecmp) 48*37c9f0a6Schristos __weak_alias(strncasecmp,_strncasecmp) 49*37c9f0a6Schristos #endif 50*37c9f0a6Schristos #else 51*37c9f0a6Schristos #include <lib/libkern/libkern.h> 52*37c9f0a6Schristos #include <machine/limits.h> 53*37c9f0a6Schristos #endif 54*37c9f0a6Schristos 55*37c9f0a6Schristos int 56*37c9f0a6Schristos strcasecmp(s1, s2) 57*37c9f0a6Schristos const char *s1, *s2; 58*37c9f0a6Schristos { 59*37c9f0a6Schristos const unsigned char *us1 = (const unsigned char *)s1, 60*37c9f0a6Schristos *us2 = (const unsigned char *)s2; 61*37c9f0a6Schristos 62*37c9f0a6Schristos _DIAGASSERT(s1 != NULL); 63*37c9f0a6Schristos _DIAGASSERT(s2 != NULL); 64*37c9f0a6Schristos 65*37c9f0a6Schristos while (tolower(*us1) == tolower(*us2++)) 66*37c9f0a6Schristos if (*us1++ == '\0') 67*37c9f0a6Schristos return (0); 68*37c9f0a6Schristos return (tolower(*us1) - tolower(*--us2)); 69*37c9f0a6Schristos } 70