ReactOS 0.4.16-dev-1025-gd3456f5
mbsupr.cpp
Go to the documentation of this file.
1/***
2*mbsupr.c - Convert string upper case (MBCS)
3*
4* Copyright (c) Microsoft Corporation. All rights reserved.
5*
6*Purpose:
7* Convert string upper case (MBCS)
8*
9*******************************************************************************/
10#ifndef _MBCS
11 #error This file should only be compiled with _MBCS defined
12#endif
13
16#include <locale.h>
17#include <string.h>
18
19#pragma warning(disable:__WARNING_POTENTIAL_BUFFER_OVERFLOW_NULLTERMINATED)
20
21/***
22* _mbsupr - Convert string upper case (MBCS)
23*
24*Purpose:
25* Converts all the lower case characters in a string
26* to upper case in place. Handles MBCS chars correctly.
27*
28*Entry:
29* unsigned char *string = pointer to string
30*
31*Exit:
32* Returns a pointer to the input string.
33* Returns nullptr on error.
34*
35*Exceptions:
36* Input parameters are validated. Refer to the validation section of the function.
37*
38*******************************************************************************/
39
41 unsigned char *string,
42 size_t sizeInBytes,
44 )
45{
46 size_t stringlen;
47
48 /* validation section */
49 _VALIDATE_RETURN_ERRCODE((string != nullptr && sizeInBytes > 0) || (string == nullptr && sizeInBytes == 0), EINVAL);
50
51 if (string == nullptr)
52 {
53 /* nothing to do */
54 return 0;
55 }
56
57 stringlen = strnlen((char *)string, sizeInBytes);
59 {
62 }
64
65 unsigned char *cp, *dst;
66 _LocaleUpdate _loc_update(plocinfo);
67
68 for (cp = string, dst = string; *cp; ++cp)
69 {
70 if ( _ismbblead_l(*cp, _loc_update.GetLocaleT()) )
71 {
72
73
74 int retval;
75 unsigned char ret[4];
76
78 _loc_update.GetLocaleT(),
79 _loc_update.GetLocaleT()->mbcinfo->mblocalename,
81 (const char *)cp,
82 2,
83 (char *)ret,
84 2,
85 _loc_update.GetLocaleT()->mbcinfo->mbcodepage,
86 TRUE )) == 0 )
87 {
88 errno = EILSEQ;
90 return errno;
91 }
92
93 *(dst++) = ret[0];
94 ++cp;
95 if (retval > 1)
96 {
97 *(dst++) = ret[1];
98 }
99
100
101 }
102 else
103 /* single byte, macro version */
104 *(dst++) = (unsigned char) _mbbtoupper_l(*cp, _loc_update.GetLocaleT());
105 }
106 /* null terminate the string */
107 *dst = '\0';
108
109 return 0;
110}
111
112extern "C" errno_t (__cdecl _mbsupr_s)(
113 unsigned char *string,
115 )
116{
117 return _mbsupr_s_l(string, sizeInBytes, nullptr);
118}
119
120extern "C" unsigned char * (__cdecl _mbsupr_l)(
121 unsigned char *string,
123 )
124{
125 return (_mbsupr_s_l(string, (string == nullptr ? 0 : (size_t)-1), plocinfo) == 0 ? string : nullptr);
126}
127
128extern "C" unsigned char * (__cdecl _mbsupr)(
129 unsigned char *string
130 )
131{
132 return (_mbsupr_s_l(string, (string == nullptr ? 0 : (size_t)-1), nullptr) == 0 ? string : nullptr);
133}
int __cdecl __acrt_LCMapStringA(_locale_t const plocinfo, PCWSTR const LocaleName, DWORD const dwMapFlags, PCCH const lpSrcStr, int const cchSrc, PCH const lpDestStr, int const cchDest, int const code_page, BOOL const bError)
#define EINVAL
Definition: acclib.h:90
#define __cdecl
Definition: accygwin.h:79
#define _ismbblead_l(_c, p)
#define _mbbtoupper_l(_c, p)
#define _RETURN_DEST_NOT_NULL_TERMINATED(_String, _Size)
#define _FILL_STRING
#define _RESET_STRING(_String, _Size)
#define TRUE
Definition: types.h:120
GLint const GLchar GLint stringlen
Definition: glext.h:7232
GLenum GLenum dst
Definition: glext.h:6340
#define _VALIDATE_RETURN_ERRCODE(expr, errorcode)
_locale_t plocinfo
Definition: ismbbyte.cpp:75
POINT cp
Definition: magnifier.c:59
unsigned char *__cdecl _mbsupr_l(unsigned char *string, _locale_t plocinfo)
Definition: mbsupr.cpp:120
size_t sizeInBytes
Definition: mbsupr.cpp:116
unsigned char *__cdecl _mbsupr(unsigned char *string)
Definition: mbsupr.cpp:128
errno_t __cdecl _mbsupr_s_l(unsigned char *string, size_t sizeInBytes, _locale_t plocinfo)
Definition: mbsupr.cpp:40
char string[160]
Definition: util.h:11
#define errno
Definition: errno.h:18
#define EILSEQ
Definition: errno.h:109
size_t __cdecl strnlen(char const *const string, size_t const maximum_count)
Definition: strnlen.cpp:202
int errno_t
Definition: corecrt.h:615
int ret
int retval
Definition: wcstombs.cpp:91
#define LCMAP_UPPERCASE
Definition: winnls.h:187