ReactOS 0.4.16-dev-927-g467dec4
mbsnbset.cpp File Reference
#include <corecrt_internal_mbstring.h>
#include <locale.h>
#include <string.h>
Include dependency graph for mbsnbset.cpp:

Go to the source code of this file.

Functions

unsigned char *__cdecl _mbsnbset_l (unsigned char *string, unsigned int val, size_t count, _locale_t plocinfo)
 
unsigned char *__cdecl _mbsnbset (unsigned char *string, unsigned int val, size_t count)
 

Function Documentation

◆ _mbsnbset()

unsigned char *__cdecl _mbsnbset ( unsigned char string,
unsigned int  val,
size_t  count 
)

Definition at line 127 of file mbsnbset.cpp.

132{
134 return _mbsnbset_l(string, val, count, nullptr);
136}
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint GLfloat * val
Definition: glext.h:7180
#define _BEGIN_SECURE_CRT_DEPRECATION_DISABLE
#define _END_SECURE_CRT_DEPRECATION_DISABLE
unsigned char *__cdecl _mbsnbset_l(unsigned char *string, unsigned int val, size_t count, _locale_t plocinfo)
Definition: mbsnbset.cpp:56

◆ _mbsnbset_l()

unsigned char *__cdecl _mbsnbset_l ( unsigned char string,
unsigned int  val,
size_t  count,
_locale_t  plocinfo 
)

Definition at line 56 of file mbsnbset.cpp.

62{
63 unsigned char *start = string;
64 unsigned char highval, lowval;
65 _LocaleUpdate _loc_update(plocinfo);
66
68 if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0)
69 return (unsigned char *)_strnset((char *)string, val, count);
71
72 /* validation section */
73 _VALIDATE_RETURN(string != nullptr || count == 0, EINVAL, nullptr);
74
75 /*
76 * leadbyte flag indicates if the last byte we overwrote was
77 * a lead byte or not.
78 */
79
80 highval = static_cast<unsigned char>(val >> 8);
81 if (highval)
82 {
83 /* double byte value */
84
85 lowval = (unsigned char)(val & 0x00ff);
86
87 if(lowval=='\0')
88 {
89 _ASSERTE(("invalid MBCS pair passed to mbsnbset",0));
90
91 /* Ideally we would return nullptr here and signal an error
92 condition. But since this function has no other
93 error modes, there would be a good chance of crashing
94 the caller. So instead we fill the string with spaces
95 to ensure that no information leaks through
96 unexpectedly. Anyway, we do set errno to EINVAL.
97 */
98 errno = EINVAL;
99 lowval=highval=' ';
100 }
101
102 while ((count--) && *string) {
103
104 /* pad with ' ' if no room for both bytes -- odd len */
105 if ((!count--) || (!*(string+1))) {
106 *string = ' ';
107 break;
108 }
109
110 *string++ = highval;
111 *string++ = lowval;
112 }
113 }
114
115 else {
116 /* single byte value */
117
118 while (count-- && *string) {
119 *string++ = (unsigned char)val;
120 }
121
122 }
123
124 return( start );
125}
#define EINVAL
Definition: acclib.h:90
#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
_locale_t plocinfo
Definition: ismbbyte.cpp:75
char string[160]
Definition: util.h:11
#define errno
Definition: errno.h:18
_strnset
Definition: string.h:393

Referenced by _mbsnbset().