blob: 2eac47dd421be86f871ab7c6651889ec6af89c92 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/*
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
30int strncasecmp(register const Wchar *s1, register const Wchar *s2, size_t n)
31{
32 return strncasecmp_l(s1, s2, n, __UCLIBC_CURLOCALE);
33}
34#ifndef WANT_WIDE
35libc_hidden_def(strncasecmp)
36#endif
37
38#else /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
39
40int __XL_NPP(strncasecmp)(register const Wchar *s1, register const Wchar *s2,
41 size_t n __LOCALE_PARAM )
42{
43#ifdef WANT_WIDE
44 while (n && ((*s1 == *s2) || (TOLOWER(*s1) == TOLOWER(*s2)))) {
45 if (!*s1++) {
46 return 0;
47 }
48 ++s2;
49 --n;
50 }
51
52 return (n == 0)
53 ? 0
54 : ((((Wuchar)TOLOWER(*s1)) < ((Wuchar)TOLOWER(*s2))) ? -1 : 1);
55 /* TODO -- should wide cmp funcs do wchar or Wuchar compares? */
56#else
57 int r = 0;
58
59 while ( n
60 && ((s1 == s2) ||
61 !(r = ((int)( TOLOWER(*((unsigned char *)s1))))
62 - TOLOWER(*((unsigned char *)s2))))
63 && (--n, ++s2, *s1++));
64 return r;
65#endif
66}
67#if !defined WANT_WIDE || (defined WANT_WIDE && defined __UCLIBC_DO_XLOCALE)
68libc_hidden_def(__XL_NPP(strncasecmp))
69#endif
70
71#endif /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */