/*-1* SPDX-License-Identifier: BSD-4-Clause2*3* Copyright (c) 1987, 19934* The Regents of the University of California. All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14* 3. All advertising materials mentioning features or use of this software15* must display the following acknowledgement:16* This product includes software developed by the University of17* California, Berkeley and its contributors.18* 4. Neither the name of the University nor the names of its contributors19* may be used to endorse or promote products derived from this software20* without specific prior written permission.21*22* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND23* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE24* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE25* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE26* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL27* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS28* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)29* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT30* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY31* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF32* SUCH DAMAGE.33*/3435#include <sys/param.h>36#include <sys/ctype.h>37#include <sys/libkern.h>3839int40strcasecmp(const char *s1, const char *s2)41{42const u_char *us1 = (const u_char *)s1, *us2 = (const u_char *)s2;4344while (tolower(*us1) == tolower(*us2)) {45if (*us1++ == '\0')46return (0);47us2++;48}49return (tolower(*us1) - tolower(*us2));50}5152int53strncasecmp(const char *s1, const char *s2, size_t n)54{5556if (n != 0) {57const u_char *us1 = (const u_char *)s1;58const u_char *us2 = (const u_char *)s2;5960do {61if (tolower(*us1) != tolower(*us2))62return (tolower(*us1) - tolower(*us2));63if (*us1++ == '\0')64break;65us2++;66} while (--n != 0);67}68return (0);69}707172