1206360Sjoel/*- 2148861Spjd * Copyright (c) 1987, 1993 3148861Spjd * The Regents of the University of California. All rights reserved. 4148861Spjd * 5148861Spjd * Redistribution and use in source and binary forms, with or without 6148861Spjd * modification, are permitted provided that the following conditions 7148861Spjd * are met: 8148861Spjd * 1. Redistributions of source code must retain the above copyright 9148861Spjd * notice, this list of conditions and the following disclaimer. 10148861Spjd * 2. Redistributions in binary form must reproduce the above copyright 11148861Spjd * notice, this list of conditions and the following disclaimer in the 12148861Spjd * documentation and/or other materials provided with the distribution. 13148861Spjd * 3. All advertising materials mentioning features or use of this software 14148861Spjd * must display the following acknowledgement: 15148861Spjd * This product includes software developed by the University of 16148861Spjd * California, Berkeley and its contributors. 17148861Spjd * 4. Neither the name of the University nor the names of its contributors 18148861Spjd * may be used to endorse or promote products derived from this software 19148861Spjd * without specific prior written permission. 20148861Spjd * 21148861Spjd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22148861Spjd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23148861Spjd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24148861Spjd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25148861Spjd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26148861Spjd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27148861Spjd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28148861Spjd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29148861Spjd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30148861Spjd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31148861Spjd * SUCH DAMAGE. 32148861Spjd */ 33148861Spjd 34148861Spjd#include <sys/cdefs.h> 35148861Spjd__FBSDID("$FreeBSD$"); 36148861Spjd 37148861Spjd#include <sys/param.h> 38148861Spjd#include <sys/ctype.h> 39148861Spjd#include <sys/libkern.h> 40148861Spjd 41148861Spjdint 42148861Spjdstrcasecmp(const char *s1, const char *s2) 43148861Spjd{ 44148861Spjd const u_char *us1 = (const u_char *)s1, *us2 = (const u_char *)s2; 45148861Spjd 46148865Spjd while (tolower(*us1) == tolower(*us2)) { 47148861Spjd if (*us1++ == '\0') 48148861Spjd return (0); 49148865Spjd us2++; 50148861Spjd } 51148865Spjd return (tolower(*us1) - tolower(*us2)); 52148861Spjd} 53148861Spjd 54148861Spjdint 55148861Spjdstrncasecmp(const char *s1, const char *s2, size_t n) 56148861Spjd{ 57148861Spjd 58148861Spjd if (n != 0) { 59148861Spjd const u_char *us1 = (const u_char *)s1; 60148861Spjd const u_char *us2 = (const u_char *)s2; 61148861Spjd 62148861Spjd do { 63148865Spjd if (tolower(*us1) != tolower(*us2)) 64148865Spjd return (tolower(*us1) - tolower(*us2)); 65148861Spjd if (*us1++ == '\0') 66148861Spjd break; 67148865Spjd us2++; 68148861Spjd } while (--n != 0); 69148861Spjd } 70148861Spjd return (0); 71148861Spjd} 72