wcscasecmp.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Copyright (C) 1991-2019 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #ifdef HAVE_CONFIG_H
  15. # include <config.h>
  16. #endif
  17. #include <wctype.h>
  18. #include <wchar.h>
  19. #ifndef weak_alias
  20. # define __wcscasecmp wcscasecmp
  21. # define TOLOWER(Ch) towlower (Ch)
  22. #else
  23. # ifdef USE_IN_EXTENDED_LOCALE_MODEL
  24. # define __wcscasecmp __wcscasecmp_l
  25. # define TOLOWER(Ch) __towlower_l ((Ch), loc)
  26. # else
  27. # define TOLOWER(Ch) towlower (Ch)
  28. # endif
  29. #endif
  30. #ifdef USE_IN_EXTENDED_LOCALE_MODEL
  31. # define LOCALE_PARAM , locale_t loc
  32. #else
  33. # define LOCALE_PARAM
  34. #endif
  35. /* Compare S1 and S2, ignoring case, returning less than, equal to or
  36. greater than zero if S1 is lexicographically less than,
  37. equal to or greater than S2. */
  38. int
  39. __wcscasecmp (const wchar_t *s1, const wchar_t *s2 LOCALE_PARAM)
  40. {
  41. wint_t c1, c2;
  42. if (s1 == s2)
  43. return 0;
  44. do
  45. {
  46. c1 = TOLOWER (*s1++);
  47. c2 = TOLOWER (*s2++);
  48. if (c1 == L'\0')
  49. break;
  50. }
  51. while (c1 == c2);
  52. return c1 - c2;
  53. }
  54. #ifndef __wcscasecmp
  55. weak_alias (__wcscasecmp, wcscasecmp)
  56. #endif