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.

130 lines
3.8 KiB

  1. /***
  2. *wcsncoll.c - Collate wide-character locale strings
  3. *
  4. * Copyright (c) 1994-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Compare two wchar_t strings using the locale LC_COLLATE information.
  8. * Compares at most n characters of two strings.
  9. *
  10. *Revision History:
  11. * 05-09-94 CFW Created from wcsnicoll.c.
  12. * 05-26-94 CFW If count is zero, return EQUAL.
  13. * 09-06-94 CFW Remove _INTL switch.
  14. * 10-25-94 GJF Sped up C locale, multi-thread case.
  15. * 09-26-95 GJF New locking macro, and scheme, for functions which
  16. * reference the locale.
  17. * 10-30-95 GJF Specify SORT_STRINGSORT to CompareString.
  18. * 07-16-96 SKS Added missing call to _unlock_locale()
  19. * 11-24-97 GJF Removed bogus codepage determination.
  20. * 01-12-98 GJF Use _lc_collate_cp codepage.
  21. * 08-13-98 GJF Revised multithread support based on threadlocinfo
  22. * struct.
  23. * 01-04-99 GJF Changes for 64-bit size_t.
  24. * 04-30-99 PML Minor cleanup as part of 64-bit merge.
  25. *
  26. *******************************************************************************/
  27. #ifndef _POSIX_
  28. #include <cruntime.h>
  29. #include <windows.h>
  30. #include <stdlib.h>
  31. #include <string.h>
  32. #include <limits.h>
  33. #include <locale.h>
  34. #include <setlocal.h>
  35. #include <mtdll.h>
  36. #include <errno.h>
  37. #include <awint.h>
  38. /***
  39. *int _wcsncoll() - Collate wide-character locale strings
  40. *
  41. *Purpose:
  42. * Compare two wchar_t strings using the locale LC_COLLATE information
  43. * Compares at most n characters of two strings.
  44. * In the C locale, _wcsncmp() is used to make the comparison.
  45. *
  46. *Entry:
  47. * const wchar_t *s1 = pointer to the first string
  48. * const wchar_t *s2 = pointer to the second string
  49. * size_t count - maximum number of characters to compare
  50. *
  51. *Exit:
  52. * -1 = first string less than second string
  53. * 0 = strings are equal
  54. * 1 = first string greater than second string
  55. * This range of return values may differ from other *cmp/*coll functions.
  56. *
  57. *Exceptions:
  58. * _NLSCMPERROR = error
  59. * errno = EINVAL
  60. *
  61. *******************************************************************************/
  62. int __cdecl _wcsncoll (
  63. const wchar_t *_string1,
  64. const wchar_t *_string2,
  65. size_t count
  66. )
  67. {
  68. #if !defined(_NTSUBSET_)
  69. int ret;
  70. #ifdef _MT
  71. pthreadlocinfo ptloci;
  72. #endif
  73. if (!count)
  74. return 0;
  75. if ( count > INT_MAX ) {
  76. errno = EINVAL;
  77. return _NLSCMPERROR;
  78. }
  79. #ifdef _MT
  80. ptloci = _getptd()->ptlocinfo;
  81. if ( ptloci != __ptlocinfo )
  82. ptloci = __updatetlocinfo();
  83. #endif
  84. #ifdef _MT
  85. if ( ptloci->lc_handle[LC_COLLATE] == _CLOCALEHANDLE )
  86. #else
  87. if ( __lc_handle[LC_COLLATE] == _CLOCALEHANDLE )
  88. #endif
  89. return wcsncmp(_string1, _string2, count);
  90. #ifdef _MT
  91. if ( 0 == (ret = __crtCompareStringW( ptloci->lc_handle[LC_COLLATE],
  92. #else
  93. if ( 0 == (ret = __crtCompareStringW( __lc_handle[LC_COLLATE],
  94. #endif
  95. SORT_STRINGSORT,
  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 wcsncmp(_string1, _string2, count);
  112. #endif
  113. }
  114. #endif /* _POSIX_ */