Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
3.7 KiB

  1. /***
  2. *wcscoll.c - Collate wide-character locale strings
  3. *
  4. * Copyright (c) 1988-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Compare two wchar_t strings using the locale LC_COLLATE information.
  8. *
  9. *Revision History:
  10. * 09-09-91 ETC Created from strcoll.c.
  11. * 04-06-92 KRS Make work without _INTL also.
  12. * 08-19-92 KRS Activate NLS support.
  13. * 09-02-92 SRW Get _INTL definition via ..\crt32.def
  14. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  15. * 04-14-93 CFW Error sets errno, cleanup.
  16. * 06-02-93 SRW ignore _INTL if _NTSUBSET_ defined.
  17. * 09-15-93 CFW Use ANSI conformant "__" names.
  18. * 09-22-93 CFW Use __crtxxx internal NLS API wrapper.
  19. * 09-29-93 GJF Merged NT SDK and Cuda versions.
  20. * 11-09-93 CFW Use LC_COLLATE code page for __crtxxx() conversion.
  21. * 02-07-94 CFW POSIXify.
  22. * 04-11-93 CFW Change NLSCMPERROR to _NLCMPERROR.
  23. * 09-06-94 CFW Remove _INTL switch.
  24. * 10-25-94 GJF Sped up C locale, multi-thread case.
  25. * 09-26-95 GJF New locking macro, and scheme, for functions which
  26. * reference the locale.
  27. * 10-30-95 GJF Specify SORT_STRINGSORT to CompareString.
  28. * 07-16-96 SKS Added missing call to _unlock_locale()
  29. * 11-24-97 GJF Removed bogus codepage determination.
  30. * 01-12-98 GJF Use _lc_collate_cp codepage.
  31. * 08-12-98 GJF Revised multithread support based on threadlocinfo
  32. * struct.
  33. *
  34. *******************************************************************************/
  35. #ifndef _POSIX_
  36. #include <cruntime.h>
  37. #include <windows.h>
  38. #include <stdlib.h>
  39. #include <string.h>
  40. #include <locale.h>
  41. #include <setlocal.h>
  42. #include <mtdll.h>
  43. #include <errno.h>
  44. #include <awint.h>
  45. /***
  46. *int wcscoll() - Collate wide-character locale strings
  47. *
  48. *Purpose:
  49. * Compare two wchar_t strings using the locale LC_COLLATE information.
  50. * In the C locale, wcscmp() is used to make the comparison.
  51. *
  52. *Entry:
  53. * const wchar_t *s1 = pointer to the first string
  54. * const wchar_t *s2 = pointer to the second string
  55. *
  56. *Exit:
  57. * -1 = first string less than second string
  58. * 0 = strings are equal
  59. * 1 = first string greater than second string
  60. * This range of return values may differ from other *cmp/*coll functions.
  61. *
  62. *Exceptions:
  63. * _NLSCMPERROR = error
  64. * errno = EINVAL
  65. *
  66. *******************************************************************************/
  67. int __cdecl wcscoll (
  68. const wchar_t *_string1,
  69. const wchar_t *_string2
  70. )
  71. {
  72. #if !defined(_NTSUBSET_)
  73. int ret;
  74. #ifdef _MT
  75. pthreadlocinfo ptloci = _getptd()->ptlocinfo;
  76. if ( ptloci != __ptlocinfo )
  77. ptloci = __updatetlocinfo();
  78. if ( ptloci->lc_handle[LC_COLLATE] == _CLOCALEHANDLE )
  79. #else
  80. if ( __lc_handle[LC_COLLATE] == _CLOCALEHANDLE )
  81. #endif
  82. return (wcscmp(_string1, _string2));
  83. #ifdef _MT
  84. if ( 0 == (ret = __crtCompareStringW( ptloci->lc_handle[LC_COLLATE],
  85. #else
  86. if ( 0 == (ret = __crtCompareStringW( __lc_handle[LC_COLLATE],
  87. #endif
  88. SORT_STRINGSORT,
  89. _string1,
  90. -1,
  91. _string2,
  92. -1,
  93. #ifdef _MT
  94. ptloci->lc_collate_cp)) )
  95. #else
  96. __lc_collate_cp)) )
  97. #endif
  98. {
  99. errno = EINVAL;
  100. return _NLSCMPERROR;
  101. }
  102. return (ret - 2);
  103. #else
  104. return wcscmp(_string1, _string2);
  105. #endif
  106. }
  107. #endif /* _POSIX_ */