strcasecmp.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. libc_hidden_def(strcasecmp)
  31. #else /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
  32. int __XL_NPP(strcasecmp)(register const Wchar *s1, register const Wchar *s2
  33. __LOCALE_PARAM )
  34. {
  35. #ifdef WANT_WIDE
  36. while ((*s1 == *s2) || (TOLOWER(*s1) == TOLOWER(*s2))) {
  37. if (!*s1++) {
  38. return 0;
  39. }
  40. ++s2;
  41. }
  42. return (((Wuchar)TOLOWER(*s1)) < ((Wuchar)TOLOWER(*s2))) ? -1 : 1;
  43. /* TODO -- should wide cmp funcs do wchar or Wuchar compares? */
  44. #else
  45. int r = 0;
  46. while ( ((s1 == s2) ||
  47. !(r = ((int)( TOLOWER(*((Wuchar *)s1))))
  48. - TOLOWER(*((Wuchar *)s2))))
  49. && (++s2, *s1++));
  50. return r;
  51. #endif
  52. }
  53. libc_hidden_def(__XL_NPP(strcasecmp))
  54. #endif /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */