strcasecmp.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 strcasecmp wcscasecmp
  13. # define strcasecmp_l wcscasecmp_l
  14. libc_hidden_proto(wcscasecmp)
  15. libc_hidden_proto(wcscasecmp_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(strcasecmp) */
  25. /* Experimentally off - libc_hidden_proto(strcasecmp_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 strcasecmp(register const Wchar *s1, register const Wchar *s2)
  39. {
  40. return strcasecmp_l(s1, s2, __UCLIBC_CURLOCALE);
  41. }
  42. libc_hidden_def(strcasecmp)
  43. #else /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
  44. /* Experimentally off - libc_hidden_proto(__XL_NPP(strcasecmp)) */
  45. int __XL_NPP(strcasecmp)(register const Wchar *s1, register const Wchar *s2
  46. __LOCALE_PARAM )
  47. {
  48. #ifdef WANT_WIDE
  49. while ((*s1 == *s2) || (TOLOWER(*s1) == TOLOWER(*s2))) {
  50. if (!*s1++) {
  51. return 0;
  52. }
  53. ++s2;
  54. }
  55. return (((Wuchar)TOLOWER(*s1)) < ((Wuchar)TOLOWER(*s2))) ? -1 : 1;
  56. /* TODO -- should wide cmp funcs do wchar or Wuchar compares? */
  57. #else
  58. int r = 0;
  59. while ( ((s1 == s2) ||
  60. !(r = ((int)( TOLOWER(*((Wuchar *)s1))))
  61. - TOLOWER(*((Wuchar *)s2))))
  62. && (++s2, *s1++));
  63. return r;
  64. #endif
  65. }
  66. libc_hidden_def(__XL_NPP(strcasecmp))
  67. #endif /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */