strcasecmp.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 <ctype.h>
  9. #include <locale.h>
  10. #ifdef WANT_WIDE
  11. # define strcasecmp wcscasecmp
  12. # define strcasecmp_l wcscasecmp_l
  13. # ifdef __UCLIBC_DO_XLOCALE
  14. # define TOLOWER(C) towlower_l((C), locale_arg)
  15. # else
  16. # define TOLOWER(C) towlower((C))
  17. # endif
  18. #else
  19. # ifdef __UCLIBC_DO_XLOCALE
  20. # define TOLOWER(C) tolower_l((C), locale_arg)
  21. # else
  22. # define TOLOWER(C) tolower((C))
  23. # endif
  24. #endif
  25. #if defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE)
  26. int strcasecmp(register const Wchar *s1, register const Wchar *s2)
  27. {
  28. return strcasecmp_l(s1, s2, __UCLIBC_CURLOCALE);
  29. }
  30. #ifndef WANT_WIDE
  31. libc_hidden_def(strcasecmp)
  32. #endif
  33. #else /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
  34. int __XL_NPP(strcasecmp)(register const Wchar *s1, register const Wchar *s2
  35. __LOCALE_PARAM )
  36. {
  37. #ifdef WANT_WIDE
  38. while ((*s1 == *s2) || (TOLOWER(*s1) == TOLOWER(*s2))) {
  39. if (!*s1++) {
  40. return 0;
  41. }
  42. ++s2;
  43. }
  44. return (((Wuchar)TOLOWER(*s1)) < ((Wuchar)TOLOWER(*s2))) ? -1 : 1;
  45. /* TODO -- should wide cmp funcs do wchar or Wuchar compares? */
  46. #else
  47. int r = 0;
  48. while ( ((s1 == s2) ||
  49. !(r = ((int)( TOLOWER(*((Wuchar *)s1))))
  50. - TOLOWER(*((Wuchar *)s2))))
  51. && (++s2, *s1++));
  52. return r;
  53. #endif
  54. }
  55. #if !defined WANT_WIDE || (defined WANT_WIDE && defined __UCLIBC_DO_XLOCALE)
  56. libc_hidden_def(__XL_NPP(strcasecmp))
  57. #endif
  58. #endif /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */