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.

78 lines
1.7 KiB

  1. /***
  2. *mbslen.c - Find length of MBCS string
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Find length of MBCS string
  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-15-93 CFW Add _MB_CP_LOCK.
  13. * 05-09-94 CFW Optimize for SBCS.
  14. * 05-19-94 CFW Enable non-Win32.
  15. * 09-11-97 GJF Replaced __mbcodepage == 0 with _ISNOTMBCP.
  16. * 04-07-98 GJF Revised multithread support based on threadmbcinfo
  17. * structs
  18. *
  19. *******************************************************************************/
  20. #ifdef _MBCS
  21. #include <mtdll.h>
  22. #include <cruntime.h>
  23. #include <string.h>
  24. #include <mbdata.h>
  25. #include <mbctype.h>
  26. #include <mbstring.h>
  27. /***
  28. * _mbslen - Find length of MBCS string
  29. *
  30. *Purpose:
  31. * Find the length of the MBCS string (in characters).
  32. *
  33. *Entry:
  34. * unsigned char *s = string
  35. *
  36. *Exit:
  37. * Returns the number of MBCS chars in the string
  38. *
  39. *Exceptions:
  40. *
  41. *******************************************************************************/
  42. size_t __cdecl _mbslen(
  43. const unsigned char *s
  44. )
  45. {
  46. int n;
  47. #ifdef _MT
  48. pthreadmbcinfo ptmbci = _getptd()->ptmbcinfo;
  49. if ( ptmbci != __ptmbcinfo )
  50. ptmbci = __updatetmbcinfo();
  51. if ( _ISNOTMBCP_MT(ptmbci) )
  52. #else
  53. if ( _ISNOTMBCP )
  54. #endif
  55. return strlen(s);
  56. for (n = 0; *s; n++, s++) {
  57. #ifdef _MT
  58. if ( __ismbblead_mt(ptmbci, *s) ) {
  59. #else
  60. if ( _ismbblead(*s) ) {
  61. #endif
  62. if (*++s == '\0')
  63. break;
  64. }
  65. }
  66. return(n);
  67. }
  68. #endif /* _MBCS */