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.

127 lines
3.7 KiB

  1. /***
  2. *strnicoll.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. * Compares at most n characters of two strings.
  9. *
  10. *Revision History:
  11. * 01-13-94 CFW Created from stricoll.c.
  12. * 04-11-93 CFW Change NLSCMPERROR to _NLCMPERROR.
  13. * 05-09-94 CFW Fix !_INTL case.
  14. * 05-26-94 CFW If count is zero, return EQUAL.
  15. * 09-06-94 CFW Remove _INTL switch.
  16. * 12-29-94 CFW Merge non-Win32.
  17. * 09-26-95 GJF New locking macro, and scheme, for functions which
  18. * reference the locale.
  19. * 10-30-95 GJF Specify SORT_STRINGSORT to CompareString.
  20. * 07-16-96 SKS Added missing call to _unlock_locale()
  21. * 11-24-97 GJF Removed bogus codepage determination.
  22. * 01-12-98 GJF Use _lc_collate_cp codepage.
  23. * 08-11-98 GJF Revised multithread support based on threadlocinfo
  24. * struct.
  25. * 01-04-99 GJF Changes for 64-bit size_t.
  26. * 04-30-99 PML Minor cleanup as part of 64-bit merge.
  27. * 05-17-99 PML Remove all Macintosh support.
  28. *
  29. *******************************************************************************/
  30. #include <cruntime.h>
  31. #include <string.h>
  32. #include <windows.h>
  33. #include <stdlib.h>
  34. #include <malloc.h>
  35. #include <limits.h>
  36. #include <locale.h>
  37. #include <setlocal.h>
  38. #include <mtdll.h>
  39. #include <errno.h>
  40. #include <awint.h>
  41. /***
  42. *int _strnicoll() - Collate locale strings without regard to case
  43. *
  44. *Purpose:
  45. * Compare two strings using the locale LC_COLLATE information
  46. * without regard to case.
  47. * Compares at most n characters of two strings.
  48. *
  49. *Entry:
  50. * const char *s1 = pointer to the first string
  51. * const char *s2 = pointer to the second string
  52. * size_t count - maximum number of characters to compare
  53. *
  54. *Exit:
  55. * Less than 0 = first string less than second string
  56. * 0 = strings are equal
  57. * Greater than 0 = first string greater than second string
  58. *
  59. *Exceptions:
  60. * _NLSCMPERROR = error
  61. * errno = EINVAL
  62. *
  63. *******************************************************************************/
  64. int __cdecl _strnicoll (
  65. const char *_string1,
  66. const char *_string2,
  67. size_t count
  68. )
  69. {
  70. #if !defined(_NTSUBSET_)
  71. int ret;
  72. #ifdef _MT
  73. pthreadlocinfo ptloci;
  74. #endif
  75. if (!count)
  76. return 0;
  77. if ( count > INT_MAX ) {
  78. errno = EINVAL;
  79. return _NLSCMPERROR;
  80. }
  81. #ifdef _MT
  82. ptloci = _getptd()->ptlocinfo;
  83. if ( ptloci != __ptlocinfo )
  84. ptloci = __updatetlocinfo();
  85. if ( ptloci->lc_handle[LC_COLLATE] == _CLOCALEHANDLE )
  86. #else
  87. if ( __lc_handle[LC_COLLATE] == _CLOCALEHANDLE )
  88. #endif
  89. return _strnicmp(_string1, _string2, count);
  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 | NORM_IGNORECASE,
  96. _string1,
  97. (int)count,
  98. _string2,
  99. (int)count,
  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 _strnicmp(_string1, _string2, count);
  112. #endif
  113. }