1872b698pfg/*- 2872b698pfg * SPDX-License-Identifier: BSD-3-Clause 3872b698pfg * 4be22b15rgrimes * Copyright (c) 1987, 1993 5be22b15rgrimes * The Regents of the University of California. All rights reserved. 6be22b15rgrimes * 70f6ef69theraven * Copyright (c) 2011 The FreeBSD Foundation 80f6ef69theraven * All rights reserved. 90f6ef69theraven * Portions of this software were developed by David Chisnall 100f6ef69theraven * under sponsorship from the FreeBSD Foundation. 110f6ef69theraven * 12be22b15rgrimes * Redistribution and use in source and binary forms, with or without 13be22b15rgrimes * modification, are permitted provided that the following conditions 14be22b15rgrimes * are met: 15be22b15rgrimes * 1. Redistributions of source code must retain the above copyright 16be22b15rgrimes * notice, this list of conditions and the following disclaimer. 17be22b15rgrimes * 2. Redistributions in binary form must reproduce the above copyright 18be22b15rgrimes * notice, this list of conditions and the following disclaimer in the 19be22b15rgrimes * documentation and/or other materials provided with the distribution. 20324e4c0emaste * 3. Neither the name of the University nor the names of its contributors 21be22b15rgrimes * may be used to endorse or promote products derived from this software 22be22b15rgrimes * without specific prior written permission. 23be22b15rgrimes * 24be22b15rgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25be22b15rgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26be22b15rgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27be22b15rgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28be22b15rgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29be22b15rgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30be22b15rgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31be22b15rgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32be22b15rgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33be22b15rgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34be22b15rgrimes * SUCH DAMAGE. 35be22b15rgrimes */ 36be22b15rgrimes 37be22b15rgrimes#if defined(LIBC_SCCS) && !defined(lint) 38be22b15rgrimesstatic char sccsid[] = "@(#)strcasecmp.c 8.1 (Berkeley) 6/4/93"; 39be22b15rgrimes#endif /* LIBC_SCCS and not lint */ 408d90001obrien#include <sys/cdefs.h> 41d1bf0c4obrien__FBSDID("$FreeBSD$"); 42d1bf0c4obrien 433d9398crobert#include <strings.h> 448d90001obrien#include <ctype.h> 450f6ef69theraven#include "xlocale_private.h" 46be22b15rgrimes 47be22b15rgrimesint 480f6ef69theravenstrcasecmp_l(const char *s1, const char *s2, locale_t locale) 49be22b15rgrimes{ 501196344obrien const u_char 51be22b15rgrimes *us1 = (const u_char *)s1, 52be22b15rgrimes *us2 = (const u_char *)s2; 530f6ef69theraven FIX_LOCALE(locale); 54be22b15rgrimes 550f6ef69theraven while (tolower_l(*us1, locale) == tolower_l(*us2++, locale)) 56be22b15rgrimes if (*us1++ == '\0') 57be22b15rgrimes return (0); 580f6ef69theraven return (tolower_l(*us1, locale) - tolower_l(*--us2, locale)); 590f6ef69theraven} 600f6ef69theravenint 610f6ef69theravenstrcasecmp(const char *s1, const char *s2) 620f6ef69theraven{ 630f6ef69theraven return strcasecmp_l(s1, s2, __get_locale()); 64be22b15rgrimes} 65be22b15rgrimes 66be22b15rgrimesint 670f6ef69theravenstrncasecmp_l(const char *s1, const char *s2, size_t n, locale_t locale) 68be22b15rgrimes{ 690f6ef69theraven FIX_LOCALE(locale); 70bdf8a55eadler if (n != 0) { 71bdf8a55eadler const u_char 72bdf8a55eadler *us1 = (const u_char *)s1, 73bdf8a55eadler *us2 = (const u_char *)s2; 74be22b15rgrimes 75bdf8a55eadler do { 76bdf8a55eadler if (tolower_l(*us1, locale) != tolower_l(*us2++, locale)) 77bdf8a55eadler return (tolower_l(*us1, locale) - tolower_l(*--us2, locale)); 78bdf8a55eadler if (*us1++ == '\0') 79bdf8a55eadler break; 80bdf8a55eadler } while (--n != 0); 81bdf8a55eadler } 82be22b15rgrimes return (0); 83be22b15rgrimes} 840f6ef69theraven 850f6ef69theravenint 860f6ef69theravenstrncasecmp(const char *s1, const char *s2, size_t n) 870f6ef69theraven{ 880f6ef69theraven return strncasecmp_l(s1, s2, n, __get_locale()); 890f6ef69theraven} 90