Reactos
at master 67 lines 1.9 kB view raw
1/*** 2*mbsnccnt.c - Return char count of MBCS string 3* 4* Copyright (c) Microsoft Corporation. All rights reserved. 5* 6*Purpose: 7* Return char count 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_mbstring.h> 15#include <locale.h> 16 17/*** 18* _mbsnccnt - Return char count of MBCS string 19* 20*Purpose: 21* Returns the number of chars between the start of the supplied 22* string and the byte count supplied. That is, this routine 23* indicates how many chars are in the first "bcnt" bytes 24* of the string. 25* 26*Entry: 27* const unsigned char *string = pointer to string 28* unsigned int bcnt = number of bytes to scan 29* 30*Exit: 31* Returns number of chars between string and bcnt. 32* 33* If the end of the string is encountered before bcnt chars were 34* scanned, then the length of the string in chars is returned. 35* 36*Exceptions: 37* Input parameters are validated. Refer to the validation section of the function. 38* 39*******************************************************************************/ 40 41extern "C" size_t __cdecl _mbsnccnt_l( 42 const unsigned char *string, 43 size_t bcnt, 44 _locale_t plocinfo 45 ) 46{ 47 size_t n; 48 _LocaleUpdate _loc_update(plocinfo); 49 50 _VALIDATE_RETURN(string != nullptr || bcnt == 0, EINVAL, 0); 51 52 for (n = 0; (bcnt-- && *string); n++, string++) { 53 if ( _ismbblead_l(*string, _loc_update.GetLocaleT()) ) { 54 if ( (!bcnt--) || (*++string == '\0')) 55 break; 56 } 57 } 58 59 return(n); 60} 61extern "C" size_t (__cdecl _mbsnccnt)( 62 const unsigned char *string, 63 size_t bcnt 64 ) 65{ 66 return _mbsnccnt_l(string, bcnt, nullptr); 67}