ReactOS 0.4.16-dev-1059-gb1cf981
mbsset.cpp
Go to the documentation of this file.
1/***
2*mbsset.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
15#include <locale.h>
16#include <string.h>
17
18/***
19* mbsset - Sets all charcaters of string to given character (MBCS)
20*
21*Purpose:
22* Sets all of characters in string (except the terminating '/0'
23* character) equal to the supplied character. Handles MBCS
24* chars correctly.
25*
26*Entry:
27* unsigned char *string = string to modify
28* unsigned int val = value to fill string with
29*
30*Exit:
31* returns string = now filled with the specified char
32*
33*Uses:
34*
35*Exceptions:
36* Input parameters are validated. Refer to the validation section of the function.
37*
38*******************************************************************************/
39
40extern "C" unsigned char * __cdecl _mbsset_l(
41 unsigned char *string,
42 unsigned int val,
44 )
45{
46 unsigned char *start = string;
47 unsigned char highval, lowval;
48 _LocaleUpdate _loc_update(plocinfo);
49
50 /* validation section */
51 _VALIDATE_RETURN(string != nullptr, EINVAL, nullptr);
52
54 if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0)
55 return (unsigned char *)_strset((char *)string, val);
57
58 highval = static_cast<unsigned char>(val >> 8);
59 if (highval != 0)
60 {
61 /* 2-byte value */
62
63 lowval = (unsigned char)(val & 0x00ff);
64
65 if(lowval=='\0')
66 {
67 _ASSERTE(("invalid MBCS pair passed to mbsset",0));
68
69 /* Ideally we would return nullptr here and signal an error
70 condition. But since this function has no other
71 error modes, there would be a good chance of crashing
72 the caller. So instead we fill the string with spaces
73 to ensure that no information leaks through
74 unexpectedly. Anyway, we do set errno to EINVAL.
75 */
76 errno = EINVAL;
77 lowval=highval=' ';
78 }
79
80 while (*string) {
81
82 *string++ = highval;
83 if (*string)
84 *string++ = lowval;
85 else
86 /* don't orphan lead byte */
87 string[-1] = ' ';
88 }
89
90 }
91
92 else {
93 /* single byte value */
94
95 while (*string)
96 *string++ = (unsigned char)val;
97 }
98
99 return(start);
100}
101
102extern "C" unsigned char * (__cdecl _mbsset)(
103 unsigned char *string,
104 unsigned int val
105 )
106{
108 return _mbsset_l(string, val, nullptr);
110}
#define EINVAL
Definition: acclib.h:90
#define __cdecl
Definition: accygwin.h:79
#define _VALIDATE_RETURN(expr, errorcode, retexpr)
#define _ASSERTE(expr)
Definition: crtdbg.h:114
unsigned char
Definition: typeof.h:29
GLuint start
Definition: gl.h:1545
GLuint GLfloat * val
Definition: glext.h:7180
#define _BEGIN_SECURE_CRT_DEPRECATION_DISABLE
#define _END_SECURE_CRT_DEPRECATION_DISABLE
_locale_t plocinfo
Definition: ismbbyte.cpp:75
unsigned char *__cdecl _mbsset_l(unsigned char *string, unsigned int val, _locale_t plocinfo)
Definition: mbsset.cpp:40
unsigned char *__cdecl _mbsset(unsigned char *string, unsigned int val)
Definition: mbsset.cpp:102
char string[160]
Definition: util.h:11
#define errno
Definition: errno.h:18
_strset
Definition: string.h:424