Reactos
at master 71 lines 2.0 kB view raw
1/*** 2*mbsnbcnt.c - Returns byte count of MBCS string 3* 4* Copyright (c) Microsoft Corporation. All rights reserved. 5* 6*Purpose: 7* Returns byte 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* _mbsnbcnt - Returns byte count of MBCS string 19* 20*Purpose: 21* Returns the number of bytes between the start of the supplied 22* string and the char count supplied. That is, this routine 23* indicates how many bytes are in the first "ccnt" characters 24* of the string. 25* 26*Entry: 27* unsigned char *string = pointer to string 28* unsigned int ccnt = number of characters to scan 29* 30*Exit: 31* Returns number of bytes between string and ccnt. 32* 33* If the end of the string is encountered before ccnt chars were 34* scanned, then the length of the string in bytes 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 _mbsnbcnt_l( 42 const unsigned char *string, 43 size_t ccnt, 44 _locale_t plocinfo 45 ) 46{ 47 unsigned char *p; 48 _LocaleUpdate _loc_update(plocinfo); 49 50 /* validation section */ 51 _VALIDATE_RETURN(string != nullptr || ccnt == 0, EINVAL, 0); 52 53 for (p = (unsigned char *)string; (ccnt-- && *p); p++) { 54 if ( _ismbblead_l(*p, _loc_update.GetLocaleT()) ) { 55 if (*++p == '\0') { 56 --p; 57 break; 58 } 59 } 60 } 61 62 return ((size_t) ((char *)p - (char *)string)); 63} 64 65extern "C" size_t (__cdecl _mbsnbcnt)( 66 const unsigned char *string, 67 size_t ccnt 68 ) 69{ 70 return _mbsnbcnt_l(string, ccnt, nullptr); 71}