strcasecmp.c 1.9 KB

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