OSDN Git Service

remove a few more empty #if/#endif pairs
[uclinux-h8/uClibc.git] / libc / string / strncasecmp.c
1 /*
2  * Copyright (C) 2002     Manuel Novoa III
3  * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
4  *
5  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
6  */
7
8 #include "_string.h"
9 #include <ctype.h>
10 #include <locale.h>
11
12 #ifdef WANT_WIDE
13 # define strncasecmp wcsncasecmp
14 # define strncasecmp_l wcsncasecmp_l
15 # ifdef __UCLIBC_DO_XLOCALE
16 #  define TOLOWER(C) towlower_l((C), locale_arg)
17 # else
18 #  define TOLOWER(C) towlower((C))
19 # endif
20 #else
21 # ifdef __UCLIBC_DO_XLOCALE
22 #  define TOLOWER(C) tolower_l((C), locale_arg)
23 # else
24 #  define TOLOWER(C) tolower((C))
25 # endif
26 #endif
27
28 #if defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE)
29
30 int strncasecmp(register const Wchar *s1, register const Wchar *s2, size_t n)
31 {
32         return strncasecmp_l(s1, s2, n, __UCLIBC_CURLOCALE);
33 }
34 libc_hidden_def(strncasecmp)
35
36 #else  /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
37
38 int __XL_NPP(strncasecmp)(register const Wchar *s1, register const Wchar *s2,
39                                           size_t n   __LOCALE_PARAM )
40 {
41 #ifdef WANT_WIDE
42         while (n && ((*s1 == *s2) || (TOLOWER(*s1) == TOLOWER(*s2)))) {
43                 if (!*s1++) {
44                         return 0;
45                 }
46                 ++s2;
47                 --n;
48         }
49
50         return (n == 0)
51                 ? 0
52                 : ((((Wuchar)TOLOWER(*s1)) < ((Wuchar)TOLOWER(*s2))) ? -1 : 1);
53         /* TODO -- should wide cmp funcs do wchar or Wuchar compares? */
54 #else
55         int r = 0;
56
57         while ( n
58                         && ((s1 == s2) ||
59                                 !(r = ((int)( TOLOWER(*((unsigned char *)s1))))
60                                   - TOLOWER(*((unsigned char *)s2))))
61                         && (--n, ++s2, *s1++));
62         return r;
63 #endif
64 }
65 libc_hidden_def(__XL_NPP(strncasecmp))
66
67 #endif /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */