1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright (c) 1987, 1993
3*4882a593Smuzhiyun * The Regents of the University of California. All rights reserved.
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Redistribution and use in source and binary forms, with or without
6*4882a593Smuzhiyun * modification, are permitted provided that the following conditions
7*4882a593Smuzhiyun * are met:
8*4882a593Smuzhiyun * 1. Redistributions of source code must retain the above copyright
9*4882a593Smuzhiyun * notice, this list of conditions and the following disclaimer.
10*4882a593Smuzhiyun * 2. Redistributions in binary form must reproduce the above copyright
11*4882a593Smuzhiyun * notice, this list of conditions and the following disclaimer in the
12*4882a593Smuzhiyun * documentation and/or other materials provided with the distribution.
13*4882a593Smuzhiyun * 4. Neither the name of the University nor the names of its contributors
14*4882a593Smuzhiyun * may be used to endorse or promote products derived from this software
15*4882a593Smuzhiyun * without specific prior written permission.
16*4882a593Smuzhiyun *
17*4882a593Smuzhiyun * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18*4882a593Smuzhiyun * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19*4882a593Smuzhiyun * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20*4882a593Smuzhiyun * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21*4882a593Smuzhiyun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*4882a593Smuzhiyun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23*4882a593Smuzhiyun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24*4882a593Smuzhiyun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25*4882a593Smuzhiyun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26*4882a593Smuzhiyun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27*4882a593Smuzhiyun * SUCH DAMAGE.
28*4882a593Smuzhiyun */
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun #ifdef HAVE_DIX_CONFIG_H
31*4882a593Smuzhiyun #include <dix-config.h>
32*4882a593Smuzhiyun #endif
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun #include <ctype.h>
35*4882a593Smuzhiyun #include "dix.h"
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun #ifndef HAVE_STRCASECMP
38*4882a593Smuzhiyun int
xstrcasecmp(const char * str1,const char * str2)39*4882a593Smuzhiyun xstrcasecmp(const char *str1, const char *str2)
40*4882a593Smuzhiyun {
41*4882a593Smuzhiyun const u_char *us1 = (const u_char *) str1, *us2 = (const u_char *) str2;
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun while (tolower(*us1) == tolower(*us2)) {
44*4882a593Smuzhiyun if (*us1++ == '\0')
45*4882a593Smuzhiyun return 0;
46*4882a593Smuzhiyun us2++;
47*4882a593Smuzhiyun }
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun return (tolower(*us1) - tolower(*us2));
50*4882a593Smuzhiyun }
51*4882a593Smuzhiyun #endif
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun #ifndef HAVE_STRNCASECMP
54*4882a593Smuzhiyun int
xstrncasecmp(const char * s1,const char * s2,size_t n)55*4882a593Smuzhiyun xstrncasecmp(const char *s1, const char *s2, size_t n)
56*4882a593Smuzhiyun {
57*4882a593Smuzhiyun if (n != 0) {
58*4882a593Smuzhiyun const u_char *us1 = (const u_char *) s1, *us2 = (const u_char *) s2;
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun do {
61*4882a593Smuzhiyun if (tolower(*us1) != tolower(*us2++))
62*4882a593Smuzhiyun return (tolower(*us1) - tolower(*--us2));
63*4882a593Smuzhiyun if (*us1++ == '\0')
64*4882a593Smuzhiyun break;
65*4882a593Smuzhiyun } while (--n != 0);
66*4882a593Smuzhiyun }
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun return 0;
69*4882a593Smuzhiyun }
70*4882a593Smuzhiyun #endif
71