Back to index

glibc  2.9
strcasecmp.c
Go to the documentation of this file.
00001 /* Copyright (C) 1991,1992,1995,1996,1997,2001,2002, 2004
00002    Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #ifdef HAVE_CONFIG_H
00021 # include <config.h>
00022 #endif
00023 
00024 #include <ctype.h>
00025 #include <string.h>
00026 
00027 #ifndef _LIBC
00028 # define __strcasecmp strcasecmp
00029 # define TOLOWER(Ch) tolower (Ch)
00030 #else
00031 # include <locale/localeinfo.h>
00032 # ifdef USE_IN_EXTENDED_LOCALE_MODEL
00033 #  define __strcasecmp __strcasecmp_l
00034 # endif
00035 # define TOLOWER(Ch) __tolower_l ((Ch), loc)
00036 #endif
00037 
00038 #ifdef USE_IN_EXTENDED_LOCALE_MODEL
00039 # define LOCALE_PARAM , loc
00040 # define LOCALE_PARAM_DECL __locale_t loc;
00041 #else
00042 # define LOCALE_PARAM
00043 # define LOCALE_PARAM_DECL
00044 #endif
00045 
00046 /* Compare S1 and S2, ignoring case, returning less than, equal to or
00047    greater than zero if S1 is lexicographically less than,
00048    equal to or greater than S2.  */
00049 int
00050 __strcasecmp (s1, s2 LOCALE_PARAM)
00051      const char *s1;
00052      const char *s2;
00053      LOCALE_PARAM_DECL
00054 {
00055 #if defined _LIBC && !defined USE_IN_EXTENDED_LOCALE_MODEL
00056   __locale_t loc = _NL_CURRENT_LOCALE;
00057 #endif
00058   const unsigned char *p1 = (const unsigned char *) s1;
00059   const unsigned char *p2 = (const unsigned char *) s2;
00060   int result;
00061 
00062   if (p1 == p2)
00063     return 0;
00064 
00065   while ((result = TOLOWER (*p1) - TOLOWER (*p2++)) == 0)
00066     if (*p1++ == '\0')
00067       break;
00068 
00069   return result;
00070 }
00071 #ifndef __strcasecmp
00072 libc_hidden_def (__strcasecmp)
00073 weak_alias (__strcasecmp, strcasecmp)
00074 #endif