OSDN Git Service

hidden_def/hidden_proto: convert all users (I hope) termios split, add some missing...
[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 libc_hidden_proto(towlower_l)
17 #  define TOLOWER(C) towlower_l((C), locale_arg)
18 # else
19 libc_hidden_proto(towlower)
20 #  define TOLOWER(C) towlower((C))
21 # endif
22 #else
23 # ifdef __UCLIBC_DO_XLOCALE
24 libc_hidden_proto(tolower_l)
25 #  define TOLOWER(C) tolower_l((C), locale_arg)
26 # else
27 libc_hidden_proto(tolower)
28 #  define TOLOWER(C) tolower((C))
29 # endif
30 #endif
31
32 #if defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE)
33
34 libc_hidden_proto(strncasecmp_l)
35
36 int strncasecmp(register const Wchar *s1, register const Wchar *s2, size_t n)
37 {
38         return strncasecmp_l(s1, s2, n, __UCLIBC_CURLOCALE);
39 }
40 libc_hidden_proto(strncasecmp)
41 libc_hidden_def(strncasecmp)
42
43 #else  /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
44
45 int __XL_NPP(strncasecmp)(register const Wchar *s1, register const Wchar *s2,
46                                           size_t n   __LOCALE_PARAM )
47 {
48 #ifdef WANT_WIDE
49         while (n && ((*s1 == *s2) || (TOLOWER(*s1) == TOLOWER(*s2)))) {
50                 if (!*s1++) {
51                         return 0;
52                 }
53                 ++s2;
54                 --n;
55         }
56
57         return (n == 0)
58                 ? 0
59                 : ((((Wuchar)TOLOWER(*s1)) < ((Wuchar)TOLOWER(*s2))) ? -1 : 1);
60         /* TODO -- should wide cmp funcs do wchar or Wuchar compares? */
61 #else
62         int r = 0;
63
64         while ( n
65                         && ((s1 == s2) ||
66                                 !(r = ((int)( TOLOWER(*((unsigned char *)s1))))
67                                   - TOLOWER(*((unsigned char *)s2))))
68                         && (--n, ++s2, *s1++));
69         return r;
70 #endif
71 }
72 libc_hidden_proto(__XL_NPP(strncasecmp))
73 libc_hidden_def(__XL_NPP(strncasecmp))
74
75 #endif /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */