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.

97 lines
2.6 KiB

  1. /***
  2. *mbsnbcol.c - Collate n bytes of two MBCS strings
  3. *
  4. * Copyright (c) 1994-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Collate n bytes of two MBCS strings
  8. *
  9. *Revision History:
  10. * 05-12-94 CFW Module created from mbs*cmp.c
  11. * 06-02-94 CFW Fix comments.
  12. * 06-03-94 CFW Fix cntrl char loop count.
  13. * 06-03-94 CFW Allow non-_INTL.
  14. * 09-06-94 CFW Allow non-_WIN32!.
  15. * 12-21-94 CFW Remove fcntrlcomp NT 3.1 hack.
  16. * 09-26-97 BWT Fix POSIX
  17. * 04-13-98 GJF Revised multithread support based on threadmbcinfo
  18. * structs
  19. * 12-18-98 GJF Changes for 64-bit size_t.
  20. * 05-17-99 PML Remove all Macintosh support.
  21. *
  22. *******************************************************************************/
  23. #ifdef _MBCS
  24. #include <awint.h>
  25. #include <mtdll.h>
  26. #include <cruntime.h>
  27. #include <internal.h>
  28. #include <mbdata.h>
  29. #include <mbctype.h>
  30. #include <string.h>
  31. #include <mbstring.h>
  32. /***
  33. * _mbsnbcoll(s1, s2, n) - Collate n bytes of two MBCS strings
  34. *
  35. *Purpose:
  36. * Collates up to n bytes of two strings for lexical order.
  37. *
  38. *Entry:
  39. * unsigned char *s1, *s2 = strings to collate
  40. * size_t n = maximum number of bytes 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 _mbsnbcoll(
  51. const unsigned char *s1,
  52. const unsigned char *s2,
  53. size_t n
  54. )
  55. {
  56. #if defined(_POSIX_)
  57. return _mbsnbcmp(s1, s2, n);
  58. #else
  59. int ret;
  60. #ifdef _MT
  61. pthreadmbcinfo ptmbci = _getptd()->ptmbcinfo;
  62. if ( ptmbci != __ptmbcinfo )
  63. ptmbci = __updatetmbcinfo();
  64. #endif
  65. if (n == 0)
  66. return 0;
  67. #ifdef _MT
  68. if ( 0 == (ret = __crtCompareStringA( ptmbci->mblcid,
  69. #else
  70. if ( 0 == (ret = __crtCompareStringA( __mblcid,
  71. #endif
  72. 0,
  73. s1,
  74. (int)n,
  75. s2,
  76. (int)n,
  77. #ifdef _MT
  78. ptmbci->mbcodepage )) )
  79. #else
  80. __mbcodepage )) )
  81. #endif
  82. return _NLSCMPERROR;
  83. return ret - 2;
  84. #endif /* _POSIX_ */
  85. }
  86. #endif /* _MBCS */