xref: /reactos/sdk/lib/ucrt/mbstring/mbslen.cpp (revision 04e0dc4a)
1 /***
2 *mbslen.c - Find length of MBCS string
3 *
4 *       Copyright (c) Microsoft Corporation.  All rights reserved.
5 *
6 *Purpose:
7 *       Find length of MBCS string
8 *
9 *******************************************************************************/
10 #ifndef _MBCS
11     #error This file should only be compiled with _MBCS defined
12 #endif
13 
14 #include <corecrt_internal.h>
15 #include <corecrt_internal_mbstring.h>
16 #include <locale.h>
17 #include <string.h>
18 
19 /***
20 * _mbslen - Find length of MBCS string
21 *
22 *Purpose:
23 *       Find the length of the MBCS string (in characters).
24 *
25 *Entry:
26 *       unsigned char *s = string
27 *
28 *Exit:
29 *       Returns the number of MBCS chars in the string.
30 *
31 *Exceptions:
32 *
33 *******************************************************************************/
34 
_mbslen_l(const unsigned char * s,_locale_t plocinfo)35 extern "C" size_t __cdecl _mbslen_l(
36         const unsigned char *s,
37         _locale_t plocinfo
38         )
39 {
40         int n;
41         _LocaleUpdate _loc_update(plocinfo);
42 
43         if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0)
44             return strlen((const char *)s);
45 
46         for (n = 0; *s; n++, s++) {
47             if ( _ismbblead_l(*s, _loc_update.GetLocaleT()) ) {
48                 if (*++s == '\0')
49                     break;
50             }
51         }
52 
53         return(n);
54 }
55 
size_t(__cdecl _mbslen)56 extern "C" size_t (__cdecl _mbslen)(
57         const unsigned char *s
58         )
59 {
60     return _mbslen_l(s, nullptr);
61 }
62