strncasecmp.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. libc_hidden_proto(wcsncasecmp)
  15. libc_hidden_proto(wcsncasecmp_l)
  16. # ifdef __UCLIBC_DO_XLOCALE
  17. libc_hidden_proto(towlower_l)
  18. # define TOLOWER(C) towlower_l((C), locale_arg)
  19. # else
  20. libc_hidden_proto(towlower)
  21. # define TOLOWER(C) towlower((C))
  22. # endif
  23. #else
  24. /* Experimentally off - libc_hidden_proto(strncasecmp) */
  25. /* Experimentally off - libc_hidden_proto(strncasecmp_l) */
  26. # ifdef __UCLIBC_DO_XLOCALE
  27. libc_hidden_proto(tolower_l)
  28. # define TOLOWER(C) tolower_l((C), locale_arg)
  29. # else
  30. #if !defined __UCLIBC_HAS_XLOCALE__ && defined __UCLIBC_HAS_CTYPE_TABLES__
  31. libc_hidden_proto(__ctype_tolower)
  32. #endif
  33. libc_hidden_proto(tolower)
  34. # define TOLOWER(C) tolower((C))
  35. # endif
  36. #endif
  37. #if defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE)
  38. int strncasecmp(register const Wchar *s1, register const Wchar *s2, size_t n)
  39. {
  40. return strncasecmp_l(s1, s2, n, __UCLIBC_CURLOCALE);
  41. }
  42. libc_hidden_def(strncasecmp)
  43. #else /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
  44. /* Experimentally off - libc_hidden_proto(__XL_NPP(strncasecmp)) */
  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. return (n == 0)
  57. ? 0
  58. : ((((Wuchar)TOLOWER(*s1)) < ((Wuchar)TOLOWER(*s2))) ? -1 : 1);
  59. /* TODO -- should wide cmp funcs do wchar or Wuchar compares? */
  60. #else
  61. int r = 0;
  62. while ( n
  63. && ((s1 == s2) ||
  64. !(r = ((int)( TOLOWER(*((unsigned char *)s1))))
  65. - TOLOWER(*((unsigned char *)s2))))
  66. && (--n, ++s2, *s1++));
  67. return r;
  68. #endif
  69. }
  70. libc_hidden_def(__XL_NPP(strncasecmp))
  71. #endif /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */