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 2013 Garrett D'Amore <garrett@damore.org>
24*2d08521bSGarrett D'Amore * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
25*2d08521bSGarrett D'Amore */
26*2d08521bSGarrett D'Amore
27*2d08521bSGarrett D'Amore /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28*2d08521bSGarrett D'Amore /* All Rights Reserved */
29*2d08521bSGarrett D'Amore
30*2d08521bSGarrett D'Amore /*
31*2d08521bSGarrett D'Amore * Portions of this source code were derived from Berkeley 4.3 BSD
32*2d08521bSGarrett D'Amore * under license from the Regents of the University of California.
33*2d08521bSGarrett D'Amore */
34*2d08521bSGarrett D'Amore
35*2d08521bSGarrett D'Amore #include "lint.h"
36*2d08521bSGarrett D'Amore #include <sys/types.h>
37*2d08521bSGarrett D'Amore #include <strings.h>
38*2d08521bSGarrett D'Amore #include <ctype.h>
39*2d08521bSGarrett D'Amore #include <locale.h>
40*2d08521bSGarrett D'Amore #include "localeimpl.h"
41*2d08521bSGarrett D'Amore #include "lctype.h"
42*2d08521bSGarrett D'Amore
43*2d08521bSGarrett D'Amore int
strcasecmp_l(const char * s1,const char * s2,locale_t loc)44*2d08521bSGarrett D'Amore strcasecmp_l(const char *s1, const char *s2, locale_t loc)
45*2d08521bSGarrett D'Amore {
46*2d08521bSGarrett D'Amore extern int ascii_strcasecmp(const char *s1, const char *s2);
47*2d08521bSGarrett D'Amore const int *cm;
48*2d08521bSGarrett D'Amore const uchar_t *us1;
49*2d08521bSGarrett D'Amore const uchar_t *us2;
50*2d08521bSGarrett D'Amore const struct lc_ctype *lct = loc->ctype;
51*2d08521bSGarrett D'Amore
52*2d08521bSGarrett D'Amore /*
53*2d08521bSGarrett D'Amore * If we are in a locale that uses the ASCII character set
54*2d08521bSGarrett D'Amore * (C or POSIX), use the fast ascii_strcasecmp() function.
55*2d08521bSGarrett D'Amore */
56*2d08521bSGarrett D'Amore if (lct->lc_is_ascii)
57*2d08521bSGarrett D'Amore return (ascii_strcasecmp(s1, s2));
58*2d08521bSGarrett D'Amore
59*2d08521bSGarrett D'Amore cm = lct->lc_trans_lower;
60*2d08521bSGarrett D'Amore us1 = (const uchar_t *)s1;
61*2d08521bSGarrett D'Amore us2 = (const uchar_t *)s2;
62*2d08521bSGarrett D'Amore
63*2d08521bSGarrett D'Amore while (cm[*us1] == cm[*us2++])
64*2d08521bSGarrett D'Amore if (*us1++ == '\0')
65*2d08521bSGarrett D'Amore return (0);
66*2d08521bSGarrett D'Amore return (cm[*us1] - cm[*(us2 - 1)]);
67*2d08521bSGarrett D'Amore }
68*2d08521bSGarrett D'Amore
69*2d08521bSGarrett D'Amore int
strcasecmp(const char * s1,const char * s2)70*2d08521bSGarrett D'Amore strcasecmp(const char *s1, const char *s2)
71*2d08521bSGarrett D'Amore {
72*2d08521bSGarrett D'Amore /* would be nice to avoid uselocale()... but I don't see how */
73*2d08521bSGarrett D'Amore return (strcasecmp_l(s1, s2, uselocale(NULL)));
74*2d08521bSGarrett D'Amore }
75