home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / mbslen.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  1KB  |  60 lines

  1. /***
  2. *mbslen.c - Find length of MBCS string
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *       Find length of MBCS string
  8. *
  9. *******************************************************************************/
  10.  
  11. #ifdef _MBCS
  12.  
  13. #include <mtdll.h>
  14. #include <cruntime.h>
  15. #include <string.h>
  16. #include <mbdata.h>
  17. #include <mbctype.h>
  18. #include <mbstring.h>
  19.  
  20.  
  21. /***
  22. * _mbslen - Find length of MBCS string
  23. *
  24. *Purpose:
  25. *       Find the length of the MBCS string (in characters).
  26. *
  27. *Entry:
  28. *       unsigned char *s = string
  29. *
  30. *Exit:
  31. *       Returns the number of MBCS chars in the string
  32. *
  33. *Exceptions:
  34. *
  35. *******************************************************************************/
  36.  
  37. size_t __cdecl _mbslen(
  38.         const unsigned char *s
  39.         )
  40. {
  41.         int n;
  42.  
  43.         if ( _ISNOTMBCP )
  44.             return strlen(s);
  45.  
  46.         _mlock(_MB_CP_LOCK);
  47.  
  48.         for (n = 0; *s; n++, s++) {
  49.                 if (_ISLEADBYTE(*s)) {
  50.                         if (*++s == '\0')
  51.                                 break;
  52.                 }
  53.         }
  54.  
  55.         _munlock(_MB_CP_LOCK);
  56.         return(n);
  57. }
  58.  
  59. #endif  /* _MBCS */
  60.