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.

97 lines
2.4 KiB

  1. /***
  2. *mbscmp.c - Compare MBCS strings
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Compare MBCS strings
  8. *
  9. *Revision History:
  10. * 11-19-92 KRS Ported from 16-bit sources.
  11. * 10-05-93 GJF Replaced _CRTAPI1 with __cdecl.
  12. * 04-12-94 CFW Make function generic.
  13. * 05-05-94 CFW Work around NT/Chico bug: CompareString ignores
  14. * control characters.
  15. * 05-09-94 CFW Optimize for SBCS, no re-scan if CompareString fixed.
  16. * 05-12-94 CFW Back to hard-coded, CompareString sort is backwards.
  17. * 05-19-94 CFW Enable non-Win32.
  18. * 09-11-97 GJF Replaced __mbcodepage == 0 with _ISNOTMBCP.
  19. * 04-06-98 GJF Revised multithread support based on threadmbcinfo
  20. * structs
  21. *
  22. *******************************************************************************/
  23. #ifdef _MBCS
  24. #include <mtdll.h>
  25. #include <cruntime.h>
  26. #include <mbdata.h>
  27. #include <mbctype.h>
  28. #include <string.h>
  29. #include <mbstring.h>
  30. /***
  31. * _mbscmp - Compare MBCS strings
  32. *
  33. *Purpose:
  34. * Compares two strings for lexical order. Strings
  35. * are compared on a character basis, not a byte basis.
  36. *
  37. *Entry:
  38. * char *s1, *s2 = strings to compare
  39. *
  40. *Exit:
  41. * returns <0 if s1 < s2
  42. * returns 0 if s1 == s2
  43. * returns >0 if s1 > s2
  44. *
  45. *Exceptions:
  46. *
  47. *******************************************************************************/
  48. int __cdecl _mbscmp(
  49. const unsigned char *s1,
  50. const unsigned char *s2
  51. )
  52. {
  53. unsigned short c1, c2;
  54. #ifdef _MT
  55. pthreadmbcinfo ptmbci = _getptd()->ptmbcinfo;
  56. if ( ptmbci != __ptmbcinfo )
  57. ptmbci = __updatetmbcinfo();
  58. if ( _ISNOTMBCP_MT(ptmbci) )
  59. #else
  60. if ( _ISNOTMBCP )
  61. #endif
  62. return strcmp(s1, s2);
  63. for (;;) {
  64. c1 = *s1++;
  65. #ifdef _MT
  66. if ( __ismbblead_mt(ptmbci, c1) )
  67. #else
  68. if ( _ismbblead(c1) )
  69. #endif
  70. c1 = ( (*s1 == '\0') ? 0 : ((c1<<8) | *s1++) );
  71. c2 = *s2++;
  72. #ifdef _MT
  73. if ( __ismbblead_mt(ptmbci, c2) )
  74. #else
  75. if ( _ismbblead(c2) )
  76. #endif
  77. c2 = ( (*s2 == '\0') ? 0 : ((c2<<8) | *s2++) );
  78. if (c1 != c2)
  79. return (c1 > c2) ? 1 : -1;
  80. if (c1 == 0)
  81. return 0;
  82. }
  83. }
  84. #endif /* _MBCS */