strcasecmp.c 1.7 KB

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