Back to index

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