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.9 KiB

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