ReactOS 0.4.16-dev-1099-g3bb27eb
mbsset_s_l.cpp
Go to the documentation of this file.
1/***
2*mbsset_s_l.c - Sets all charcaters of string to given character (MBCS)
3*
4* Copyright (c) Microsoft Corporation. All rights reserved.
5*
6*Purpose:
7* Sets all charcaters of string to given character (MBCS)
8*
9*******************************************************************************/
10#ifndef _MBCS
11 #error This file should only be compiled with _MBCS defined
12#endif
13
16
17errno_t __cdecl _mbsset_s_l(unsigned char *_Dst, size_t _SizeInBytes, unsigned int _Value, _LOCALE_ARG_DECL)
18{
19 int mbcs_error = 0;
20 unsigned char *p;
21 size_t available;
22 unsigned char highval, lowval;
23
24 /* validation section */
26
29 {
30 return _strset_s((char *)_Dst, _SizeInBytes, (int)_Value);
31 }
32
33 p = _Dst;
35 highval = (unsigned char)(_Value >> 8);
36 lowval = (unsigned char)(_Value & 0x00ff);
37
38 /* ensure _Value is a valid mbchar */
39 if ((highval != 0 && (lowval == 0 || !_ISMBBLEAD(highval))) ||
40 (highval == 0 && _ISMBBLEAD(lowval)))
41 {
44 }
45
46 if (highval != 0)
47 {
48 while (*p != 0 && --available > 0)
49 {
50 if (p[1] == 0)
51 {
52 /* do not orphan leadbyte */
53 *p = 0;
54 ++available;
55 mbcs_error = 1;
56 break;
57 }
58 *p++ = highval;
59 if (--available == 0)
60 {
61 break;
62 }
63 *p++ = lowval;
64 }
65 }
66 else
67 {
68 while (*p != 0 && --available > 0)
69 {
70 *p++ = lowval;
71 }
72 }
73
74 if (available == 0)
75 {
78 }
80
81 if (mbcs_error)
82 {
84 }
85 else
86 {
88 }
89}
#define __cdecl
Definition: accygwin.h:79
#define _LOCALE_ARG_DECL
#define _RETURN_DEST_NOT_NULL_TERMINATED(_String, _Size)
#define _FILL_STRING
#define _LOCALE_SHORTCUT_TEST
#define _RESET_STRING(_String, _Size)
#define _RETURN_NO_ERROR
#define _LOCALE_UPDATE
#define _RETURN_MBCS_ERROR
#define _ISMBBLEAD(_Character)
#define _VALIDATE_STRING(_String, _Size)
_In_ _Value
static WCHAR available[MAX_STRING_RESOURCE_LEN]
Definition: object.c:2336
_Check_return_wat_ _CRTIMP errno_t __cdecl _strset_s(_Inout_updates_z_(size) char *dst, _In_ size_t size, _In_ int val)
Definition: stubs.c:660
unsigned char
Definition: typeof.h:29
GLfloat GLfloat p
Definition: glext.h:8902
errno_t __cdecl _mbsset_s_l(unsigned char *_Dst, size_t _SizeInBytes, unsigned int _Value, _LOCALE_ARG_DECL)
Definition: mbsset_s_l.cpp:17
_In_ size_t _SizeInBytes
Definition: time.h:146
int errno_t
Definition: corecrt.h:615