Leaked source code of windows server 2003
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.

124 lines
4.2 KiB

  1. /***
  2. *strcoll.c - Collate locale strings
  3. *
  4. * Copyright (c) 1988-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Compare two strings using the locale LC_COLLATE information.
  8. *
  9. *Revision History:
  10. * 03-21-89 JCR Module created.
  11. * 06-20-89 JCR Removed _LOAD_DGROUP code
  12. * 02-27-90 GJF Fixed calling type, #include <cruntime.h>, fixed
  13. * copyright.
  14. * 10-01-90 GJF New-style function declarator.
  15. * 10-01-91 ETC Non-C locale support under _INTL switch.
  16. * 12-09-91 ETC Updated api; added multithread.
  17. * 08-19-92 KRS Activate NLS support.
  18. * 09-02-92 SRW Get _INTL definition via ..\crt32.def
  19. * 12-16-92 KRS Optimize for CompareStringW by using -1 for string len.
  20. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  21. * 04-14-93 CFW Error sets errno, cleanup.
  22. * 06-02-93 SRW ignore _INTL if _NTSUBSET_ defined.
  23. * 09-15-93 CFW Use ANSI conformant "__" names.
  24. * 09-22-93 CFW Use __crtxxx internal NLS API wrapper.
  25. * 09-29-93 GJF Merged NT SDK and Cuda versions.
  26. * 11-09-93 CFW Use LC_COLLATE code page for __crtxxx() conversion.
  27. * 04-11-93 CFW Change NLSCMPERROR to _NLCMPERROR.
  28. * 09-06-94 CFW Remove _INTL switch.
  29. * 10-24-94 GJF Sped up C locale, multi-thread case.
  30. * 12-29-94 CFW Merge non-Win32.
  31. * 09-26-95 GJF New locking macro, and scheme, for functions which
  32. * reference the locale.
  33. * 10-30-95 GJF Specify SORT_STRINGSORT to CompareString.
  34. * 07-16-96 SKS Added missing call to _unlock_locale()
  35. * 11-24-97 GJF Removed bogus codepage determination.
  36. * 01-12-98 GJF Use _lc_collate_cp codepage.
  37. * 08-10-98 GJF Revised multithread support based on threadlocinfo
  38. * struct.
  39. * 05-17-99 PML Remove all Macintosh support.
  40. *
  41. *******************************************************************************/
  42. #include <cruntime.h>
  43. #include <string.h>
  44. #include <windows.h>
  45. #include <stdlib.h>
  46. #include <malloc.h>
  47. #include <locale.h>
  48. #include <setlocal.h>
  49. #include <mtdll.h>
  50. #include <errno.h>
  51. #include <awint.h>
  52. /***
  53. *int strcoll() - Collate locale strings
  54. *
  55. *Purpose:
  56. * Compare two strings using the locale LC_COLLATE information.
  57. * [ANSI].
  58. *
  59. * Non-C locale support available under _INTL switch.
  60. * In the C locale, strcoll() simply resolves to strcmp().
  61. *Entry:
  62. * const char *s1 = pointer to the first string
  63. * const char *s2 = pointer to the second string
  64. *
  65. *Exit:
  66. * Less than 0 = first string less than second string
  67. * 0 = strings are equal
  68. * Greater than 0 = first string greater than second string
  69. *
  70. *Exceptions:
  71. * _NLSCMPERROR = error
  72. * errno = EINVAL
  73. *
  74. *******************************************************************************/
  75. int __cdecl strcoll (
  76. const char *_string1,
  77. const char *_string2
  78. )
  79. {
  80. #if !defined(_NTSUBSET_)
  81. int ret;
  82. #ifdef _MT
  83. pthreadlocinfo ptloci = _getptd()->ptlocinfo;
  84. if ( ptloci != __ptlocinfo )
  85. ptloci = __updatetlocinfo();
  86. if ( ptloci->lc_handle[LC_COLLATE] == _CLOCALEHANDLE )
  87. #endif
  88. if ( __lc_handle[LC_COLLATE] == _CLOCALEHANDLE )
  89. return strcmp(_string1, _string2);
  90. #ifdef _MT
  91. if ( 0 == (ret = __crtCompareStringA( ptloci->lc_handle[LC_COLLATE],
  92. #else
  93. if ( 0 == (ret = __crtCompareStringA( __lc_handle[LC_COLLATE],
  94. #endif
  95. SORT_STRINGSORT,
  96. _string1,
  97. -1,
  98. _string2,
  99. -1,
  100. #ifdef _MT
  101. ptloci->lc_collate_cp )) )
  102. #else
  103. __lc_collate_cp )) )
  104. #endif
  105. {
  106. errno = EINVAL;
  107. return _NLSCMPERROR;
  108. }
  109. return (ret - 2);
  110. #else
  111. return strcmp(_string1,_string2);
  112. #endif
  113. }