1*2d08521bSGarrett D'Amore /* 2*2d08521bSGarrett D'Amore * CDDL HEADER START 3*2d08521bSGarrett D'Amore * 4*2d08521bSGarrett D'Amore * The contents of this file are subject to the terms of the 5*2d08521bSGarrett D'Amore * Common Development and Distribution License (the "License"). 6*2d08521bSGarrett D'Amore * You may not use this file except in compliance with the License. 7*2d08521bSGarrett D'Amore * 8*2d08521bSGarrett D'Amore * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*2d08521bSGarrett D'Amore * or http://www.opensolaris.org/os/licensing. 10*2d08521bSGarrett D'Amore * See the License for the specific language governing permissions 11*2d08521bSGarrett D'Amore * and limitations under the License. 12*2d08521bSGarrett D'Amore * 13*2d08521bSGarrett D'Amore * When distributing Covered Code, include this CDDL HEADER in each 14*2d08521bSGarrett D'Amore * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*2d08521bSGarrett D'Amore * If applicable, add the following below this CDDL HEADER, with the 16*2d08521bSGarrett D'Amore * fields enclosed by brackets "[]" replaced with your own identifying 17*2d08521bSGarrett D'Amore * information: Portions Copyright [yyyy] [name of copyright owner] 18*2d08521bSGarrett D'Amore * 19*2d08521bSGarrett D'Amore * CDDL HEADER END 20*2d08521bSGarrett D'Amore */ 21*2d08521bSGarrett D'Amore 22*2d08521bSGarrett D'Amore /* 23*2d08521bSGarrett D'Amore * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved. 24*2d08521bSGarrett D'Amore * Copyright 2013 Garrett D'Amore <garrett@damore.org> 25*2d08521bSGarrett D'Amore */ 26*2d08521bSGarrett D'Amore 27*2d08521bSGarrett D'Amore /* 28*2d08521bSGarrett D'Amore * Compare strings ignoring case difference. 29*2d08521bSGarrett D'Amore * returns: s1>s2: >0 s1==s2: 0 s1<s2: <0 30*2d08521bSGarrett D'Amore * All letters are converted to the lowercase and compared. 31*2d08521bSGarrett D'Amore */ 32*2d08521bSGarrett D'Amore 33*2d08521bSGarrett D'Amore #include "lint.h" 34*2d08521bSGarrett D'Amore #include <stdlib.h> 35*2d08521bSGarrett D'Amore #include <wchar.h> 36*2d08521bSGarrett D'Amore #include <locale.h> 37*2d08521bSGarrett D'Amore #include "libc.h" 38*2d08521bSGarrett D'Amore 39*2d08521bSGarrett D'Amore /* Legacy Sun interfaces */ 40*2d08521bSGarrett D'Amore #pragma weak wscasecmp = wcscasecmp 41*2d08521bSGarrett D'Amore #pragma weak wsncasecmp = wcsncasecmp 42*2d08521bSGarrett D'Amore 43*2d08521bSGarrett D'Amore int 44*2d08521bSGarrett D'Amore wcscasecmp_l(const wchar_t *s1, const wchar_t *s2, locale_t loc) 45*2d08521bSGarrett D'Amore { 46*2d08521bSGarrett D'Amore if (s1 == s2) 47*2d08521bSGarrett D'Amore return (0); 48*2d08521bSGarrett D'Amore 49*2d08521bSGarrett D'Amore while (towlower_l(*s1, loc) == towlower_l(*s2, loc)) { 50*2d08521bSGarrett D'Amore if (*s1 == 0) 51*2d08521bSGarrett D'Amore return (0); 52*2d08521bSGarrett D'Amore s1++; 53*2d08521bSGarrett D'Amore s2++; 54*2d08521bSGarrett D'Amore } 55*2d08521bSGarrett D'Amore return (towlower_l(*s1, loc) - towlower_l(*s2, loc)); 56*2d08521bSGarrett D'Amore } 57*2d08521bSGarrett D'Amore 58*2d08521bSGarrett D'Amore int 59*2d08521bSGarrett D'Amore wcscasecmp(const wchar_t *s1, const wchar_t *s2) 60*2d08521bSGarrett D'Amore { 61*2d08521bSGarrett D'Amore return (wcscasecmp_l(s1, s2, uselocale(NULL))); 62*2d08521bSGarrett D'Amore } 63*2d08521bSGarrett D'Amore 64*2d08521bSGarrett D'Amore int 65*2d08521bSGarrett D'Amore wcsncasecmp_l(const wchar_t *s1, const wchar_t *s2, size_t n, locale_t loc) 66*2d08521bSGarrett D'Amore { 67*2d08521bSGarrett D'Amore if (s1 == s2) 68*2d08521bSGarrett D'Amore return (0); 69*2d08521bSGarrett D'Amore 70*2d08521bSGarrett D'Amore while ((towlower_l(*s1, loc) == towlower_l(*s2, loc)) && n--) { 71*2d08521bSGarrett D'Amore if (*s1 == 0) 72*2d08521bSGarrett D'Amore return (0); 73*2d08521bSGarrett D'Amore s1++; 74*2d08521bSGarrett D'Amore s2++; 75*2d08521bSGarrett D'Amore } 76*2d08521bSGarrett D'Amore return (towlower_l(*s1, loc) - towlower_l(*s2, loc)); 77*2d08521bSGarrett D'Amore } 78*2d08521bSGarrett D'Amore 79*2d08521bSGarrett D'Amore int 80*2d08521bSGarrett D'Amore wcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n) 81*2d08521bSGarrett D'Amore { 82*2d08521bSGarrett D'Amore return (wcsncasecmp_l(s1, s2, n, uselocale(NULL))); 83*2d08521bSGarrett D'Amore } 84