/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 1987, 19934* The Regents of the University of California. All rights reserved.5*6* Copyright (c) 2011 The FreeBSD Foundation7*8* Portions of this software were developed by David Chisnall9* under sponsorship from the FreeBSD Foundation.10*11* Redistribution and use in source and binary forms, with or without12* modification, are permitted provided that the following conditions13* are met:14* 1. Redistributions of source code must retain the above copyright15* notice, this list of conditions and the following disclaimer.16* 2. Redistributions in binary form must reproduce the above copyright17* notice, this list of conditions and the following disclaimer in the18* documentation and/or other materials provided with the distribution.19* 3. Neither the name of the University nor the names of its contributors20* may be used to endorse or promote products derived from this software21* without specific prior written permission.22*23* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND24* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE25* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE26* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE27* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL28* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS29* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)30* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT31* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY32* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF33* SUCH DAMAGE.34*/3536#include <strings.h>37#include <ctype.h>38#include "xlocale_private.h"3940int41strcasecmp_l(const char *s1, const char *s2, locale_t locale)42{43const u_char44*us1 = (const u_char *)s1,45*us2 = (const u_char *)s2;46FIX_LOCALE(locale);4748while (tolower_l(*us1, locale) == tolower_l(*us2++, locale))49if (*us1++ == '\0')50return (0);51return (tolower_l(*us1, locale) - tolower_l(*--us2, locale));52}53int54strcasecmp(const char *s1, const char *s2)55{56return strcasecmp_l(s1, s2, __get_locale());57}5859int60strncasecmp_l(const char *s1, const char *s2, size_t n, locale_t locale)61{62FIX_LOCALE(locale);63if (n != 0) {64const u_char65*us1 = (const u_char *)s1,66*us2 = (const u_char *)s2;6768do {69if (tolower_l(*us1, locale) != tolower_l(*us2++, locale))70return (tolower_l(*us1, locale) - tolower_l(*--us2, locale));71if (*us1++ == '\0')72break;73} while (--n != 0);74}75return (0);76}7778int79strncasecmp(const char *s1, const char *s2, size_t n)80{81return strncasecmp_l(s1, s2, n, __get_locale());82}838485