Update.
[glibc.git] / sysdeps / generic / strcasecmp.c
blob4640372ebdc912daded205be1933dd49b655d06a
1 /* Copyright (C) 1991, 1992, 1995, 1996, 1997 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
23 #include <ctype.h>
24 #include <string.h>
26 #ifndef weak_alias
27 # define __strcasecmp strcasecmp
28 # define TOLOWER(Ch) tolower (Ch)
29 #else
30 # ifdef USE_IN_EXTENDED_LOCALE_MODEL
31 # define __strcasecmp __strcasecmp_l
32 # define TOLOWER(Ch) __tolower_l ((Ch), loc)
33 # else
34 # define TOLOWER(Ch) tolower (Ch)
35 # endif
36 #endif
38 #ifdef USE_IN_EXTENDED_LOCALE_MODEL
39 # define LOCALE_PARAM , loc
40 # define LOCALE_PARAM_DECL __locale_t loc;
41 #else
42 # define LOCALE_PARAM
43 # define LOCALE_PARAM_DECL
44 #endif
46 /* Compare S1 and S2, ignoring case, returning less than, equal to or
47 greater than zero if S1 is lexicographically less than,
48 equal to or greater than S2. */
49 int
50 __strcasecmp (s1, s2 LOCALE_PARAM)
51 const char *s1;
52 const char *s2;
53 LOCALE_PARAM_DECL
55 const unsigned char *p1 = (const unsigned char *) s1;
56 const unsigned char *p2 = (const unsigned char *) s2;
57 unsigned char c1, c2;
59 if (p1 == p2)
60 return 0;
64 c1 = TOLOWER (*p1++);
65 c2 = TOLOWER (*p2++);
66 if (c1 == '\0')
67 break;
69 while (c1 == c2);
71 return c1 - c2;
73 #ifndef __strcasecmp
74 weak_alias (__strcasecmp, strcasecmp)
75 #endif