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.

105 lines
2.8 KiB

  1. /***
  2. *mbsncol.c - Collate n characters of two MBCS strings
  3. *
  4. * Copyright (c) 1994-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Collate n characters of two MBCS strings
  8. *
  9. *Revision History:
  10. * 05-12-94 CFW Module created from mbs*cmp.c
  11. * 06-03-94 CFW Allow non-_INTL.
  12. * 07-26-94 CFW Fix for bug #13384.
  13. * 09-06-94 CFW Allow non-_WIN32!.
  14. * 12-21-94 CFW Remove fcntrlcomp NT 3.1 hack.
  15. * 09-26-97 BWT Fix POSIX
  16. * 04-16-98 GJF Implemented multithread support based on threadmbcinfo
  17. * structs
  18. * 12-18-98 GJF Changes for 64-bit size_t.
  19. * 05-17-99 PML Remove all Macintosh support.
  20. *
  21. *******************************************************************************/
  22. #ifdef _MBCS
  23. #include <awint.h>
  24. #include <mtdll.h>
  25. #include <cruntime.h>
  26. #include <internal.h>
  27. #include <mbdata.h>
  28. #include <mbctype.h>
  29. #include <string.h>
  30. #include <mbstring.h>
  31. /***
  32. * _mbsncoll(s1, s2, n) - Collate n characters of two MBCS strings
  33. *
  34. *Purpose:
  35. * Collates up to n charcters of two strings for lexical order.
  36. * Strings are collated on a character basis, not a byte basis.
  37. *
  38. *Entry:
  39. * unsigned char *s1, *s2 = strings to collate
  40. * size_t n = maximum number of characters to collate
  41. *
  42. *Exit:
  43. * returns <0 if s1 < s2
  44. * returns 0 if s1 == s2
  45. * returns >0 if s1 > s2
  46. *
  47. *Exceptions:
  48. *
  49. *******************************************************************************/
  50. int __cdecl _mbsncoll(
  51. const unsigned char *s1,
  52. const unsigned char *s2,
  53. size_t n
  54. )
  55. {
  56. #if defined (_POSIX_)
  57. return _mbsncmp(s1, s2, n);
  58. #else
  59. int ret;
  60. size_t bcnt1, bcnt2;
  61. #ifdef _MT
  62. pthreadmbcinfo ptmbci = _getptd()->ptmbcinfo;
  63. if ( ptmbci != __ptmbcinfo )
  64. ptmbci = __updatetmbcinfo();
  65. #endif
  66. if (n == 0)
  67. return 0;
  68. #ifdef _MT
  69. bcnt1 = __mbsnbcnt_mt(ptmbci, s1, n);
  70. bcnt2 = __mbsnbcnt_mt(ptmbci, s2, n);
  71. #else
  72. bcnt1 = _mbsnbcnt(s1, n);
  73. bcnt2 = _mbsnbcnt(s2, n);
  74. #endif
  75. #ifdef _MT
  76. if ( 0 == (ret = __crtCompareStringA( ptmbci->mblcid,
  77. #else
  78. if ( 0 == (ret = __crtCompareStringA( __mblcid,
  79. #endif
  80. 0,
  81. s1,
  82. (int)bcnt1,
  83. s2,
  84. (int)bcnt2,
  85. #ifdef _MT
  86. ptmbci->mbcodepage )) )
  87. #else
  88. __mbcodepage )) )
  89. #endif
  90. return _NLSCMPERROR;
  91. return ret - 2;
  92. #endif /* _POSIX_ */
  93. }
  94. #endif /* _MBCS */