strncasecmp.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #include "_string.h"
  8. #include <strings.h>
  9. #include <ctype.h>
  10. #include <locale.h>
  11. #ifdef WANT_WIDE
  12. # define strncasecmp wcsncasecmp
  13. # define strncasecmp_l wcsncasecmp_l
  14. # ifdef __UCLIBC_DO_XLOCALE
  15. libc_hidden_proto(towlower_l)
  16. # define TOLOWER(C) towlower_l((C), locale_arg)
  17. # else
  18. libc_hidden_proto(towlower)
  19. # define TOLOWER(C) towlower((C))
  20. # endif
  21. #else
  22. # ifdef __UCLIBC_DO_XLOCALE
  23. libc_hidden_proto(tolower_l)
  24. # define TOLOWER(C) tolower_l((C), locale_arg)
  25. # else
  26. #if !defined __UCLIBC_HAS_XLOCALE__ && defined __UCLIBC_HAS_CTYPE_TABLES__
  27. libc_hidden_proto(__ctype_tolower)
  28. #endif
  29. libc_hidden_proto(tolower)
  30. # define TOLOWER(C) tolower((C))
  31. # endif
  32. #endif
  33. #if defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE)
  34. /* Experimentally off - libc_hidden_proto(strncasecmp_l) */
  35. /* Experimentally off - libc_hidden_proto(strncasecmp) */
  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_def(strncasecmp)
  41. #else /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
  42. libc_hidden_proto(__XL_NPP(strncasecmp))
  43. int __XL_NPP(strncasecmp)(register const Wchar *s1, register const Wchar *s2,
  44. size_t n __LOCALE_PARAM )
  45. {
  46. #ifdef WANT_WIDE
  47. while (n && ((*s1 == *s2) || (TOLOWER(*s1) == TOLOWER(*s2)))) {
  48. if (!*s1++) {
  49. return 0;
  50. }
  51. ++s2;
  52. --n;
  53. }
  54. return (n == 0)
  55. ? 0
  56. : ((((Wuchar)TOLOWER(*s1)) < ((Wuchar)TOLOWER(*s2))) ? -1 : 1);
  57. /* TODO -- should wide cmp funcs do wchar or Wuchar compares? */
  58. #else
  59. int r = 0;
  60. while ( n
  61. && ((s1 == s2) ||
  62. !(r = ((int)( TOLOWER(*((unsigned char *)s1))))
  63. - TOLOWER(*((unsigned char *)s2))))
  64. && (--n, ++s2, *s1++));
  65. return r;
  66. #endif
  67. }
  68. libc_hidden_def(__XL_NPP(strncasecmp))
  69. #endif /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */