1 /* Copyright (C) 1991, 1992, 1995, 1996, 1997 Free Software Foundation, Inc.
2 
3    NOTE: The canonical source of this file is maintained with the GNU C Library.
4    Bugs can be reported to bug-glibc@prep.ai.mit.edu.
5 
6    This program is free software; you can redistribute it and/or modify it
7    under the terms of the GNU General Public License as published by the
8    Free Software Foundation; either version 2, or (at your option) any
9    later version.
10 
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15 
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19    USA.  */
20 
21 #ifdef HAVE_CONFIG_H
22 #  include <config.h>
23 #endif
24 #ifdef HAVE_SUPPORT_H
25 #  include "support.h"
26 #endif
27 
28 #ifdef HAVE_STRING_H
29 #  include <string.h>
30 #endif
31 
32 #include <ctype.h>
33 
34 #ifndef weak_alias
35 # define __strcasecmp strcasecmp
36 # define TOLOWER(Ch) tolower (Ch)
37 #else
38 # ifdef USE_IN_EXTENDED_LOCALE_MODEL
39 #  define __strcasecmp __strcasecmp_l
40 #  define TOLOWER(Ch) __tolower_l ((Ch), loc)
41 # else
42 #  define TOLOWER(Ch) tolower (Ch)
43 # endif
44 #endif
45 
46 #ifdef USE_IN_EXTENDED_LOCALE_MODEL
47 # define LOCALE_PARAM , loc
48 # define LOCALE_PARAM_DECL __locale_t loc;
49 #else
50 # define LOCALE_PARAM
51 # define LOCALE_PARAM_DECL
52 #endif
53 
54 /* Compare S1 and S2, ignoring case, returning less than, equal to or
55    greater than zero if S1 is lexicographically less than,
56    equal to or greater than S2.  */
57 int
58 __strcasecmp (s1, s2 LOCALE_PARAM)
59      const char *s1;
60      const char *s2;
61      LOCALE_PARAM_DECL
62 {
63   const unsigned char *p1 = (const unsigned char *) s1;
64   const unsigned char *p2 = (const unsigned char *) s2;
65   unsigned char c1, c2;
66 
67   if (p1 == p2)
68     return 0;
69 
70   do
71     {
72       c1 = TOLOWER (*p1++);
73       c2 = TOLOWER (*p2++);
74       if (c1 == '\0')
75 	break;
76     }
77   while (c1 == c2);
78 
79   return c1 - c2;
80 }
81 #ifndef __strcasecmp
82 weak_alias (__strcasecmp, strcasecmp)
83 #endif
84