Reactos
at master 64 lines 1.8 kB view raw
1/*** 2*mbsnextc.c - Get the next character in an MBCS string. 3* 4* Copyright (c) Microsoft Corporation. All rights reserved. 5* 6*Purpose: 7* To return the value of the next character in an 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#include <stdlib.h> 17 18#pragma warning(disable:__WARNING_POTENTIAL_BUFFER_OVERFLOW_NULLTERMINATED) // 26018 19 20/*** 21*_mbsnextc: Returns the next character in a string. 22* 23*Purpose: 24* To return the value of the next character in an MBCS string. 25* Does not advance pointer to the next character. 26* 27*Entry: 28* unsigned char *s = string 29* 30*Exit: 31* unsigned int next = next character. 32* 33*Exceptions: 34* Input parameters are validated. Refer to the validation section of the function. 35* 36*******************************************************************************/ 37 38extern "C" unsigned int __cdecl _mbsnextc_l( 39 const unsigned char *s, 40 _locale_t plocinfo 41 ) 42{ 43 unsigned int next = 0; 44 _LocaleUpdate _loc_update(plocinfo); 45 46 /* validation section */ 47 _VALIDATE_RETURN(s != nullptr, EINVAL, 0); 48 49 /* don't skip forward 2 if the leadbyte is followed by EOS (dud string) 50 also don't assert as we are too low-level 51 */ 52 if ( _ismbblead_l(*s, _loc_update.GetLocaleT()) && s[1]!='\0') 53 next = ((unsigned int) *s++) << 8; 54 55 next += (unsigned int) *s; 56 57 return(next); 58} 59extern "C" unsigned int (__cdecl _mbsnextc)( 60 const unsigned char *s 61 ) 62{ 63 return _mbsnextc_l(s, nullptr); 64}