ReactOS 0.4.16-dev-1093-g93e9710
wcsupr.cpp
Go to the documentation of this file.
1/***
2*wcsupr.c - routine to map lower-case characters in a wchar_t string
3* to upper-case
4*
5* Copyright (c) Microsoft Corporation. All rights reserved.
6*
7*Purpose:
8* Converts all the lower case characters in a wchar_t string
9* to upper case, in place.
10*
11*******************************************************************************/
12#include <corecrt_internal.h>
13#include <ctype.h>
15#include <locale.h>
16#include <string.h>
17
18#pragma warning(disable:__WARNING_POTENTIAL_BUFFER_OVERFLOW_NULLTERMINATED) // 26018
19
20/***
21*wchar_t *_wcsupr(string) - map lower-case characters in a string to upper-case
22*
23*Purpose:
24* wcsupr converts lower-case characters in a null-terminated wchar_t
25* string to their upper-case equivalents. The result may be longer or
26* shorter than the original string. Assumes enough space in string
27* to hold the result.
28*
29*Entry:
30* wchar_t *wsrc - wchar_t string to change to upper case
31*
32*Exit:
33* input string address
34*
35*Exceptions:
36* on an error, the original string is unaltered, and errno is set
37*
38*******************************************************************************/
39
40extern "C" wchar_t * __cdecl _wcsupr_l (
41 wchar_t * wsrc,
43 )
44{
45 _wcsupr_s_l(wsrc, (size_t)(-1), plocinfo);
46 return wsrc;
47}
48
49extern "C" wchar_t * __cdecl _wcsupr (
50 wchar_t * wsrc
51 )
52{
53 if (!__acrt_locale_changed())
54 {
55 wchar_t * p;
56
57 /* validation section */
58 _VALIDATE_RETURN(wsrc != nullptr, EINVAL, nullptr);
59
60 for (p=wsrc; *p; ++p)
61 {
62 if (L'a' <= *p && *p <= L'z')
63 *p += (wchar_t)(L'A' - L'a');
64 }
65
66 return wsrc;
67 }
68 else
69 {
70 _wcsupr_s_l(wsrc, (size_t)(-1), nullptr);
71 return wsrc;
72 }
73}
74
75/***
76*errno_t _wcsupr_s(string, size_t) - map lower-case characters in a string to upper-case
77*
78*Purpose:
79* wcsupr converts lower-case characters in a null-terminated wchar_t
80* string to their upper-case equivalents. The result may be longer or
81* shorter than the original string.
82*
83*Entry:
84* wchar_t *wsrc - wchar_t string to change to upper case
85* size_t sizeInWords - size of the destination buffer
86*
87*Exit:
88* the error code
89*
90*Exceptions:
91* on an error, the original string is unaltered, and errno is set
92*
93*******************************************************************************/
94
96 _Inout_updates_z_(sizeInWords) wchar_t * const wsrc,
97 size_t const sizeInWords,
99 )
100{
101
102 wchar_t *p; /* traverses string for C locale conversion */
103 int dstsize; /* size in wide chars of wdst string buffer (include null) */
104
105 /* validation section */
106 _VALIDATE_RETURN_ERRCODE(wsrc != nullptr, EINVAL);
107 size_t const stringlen = wcsnlen(wsrc, sizeInWords);
108 if (stringlen >= sizeInWords)
109 {
110 _RESET_STRING(wsrc, sizeInWords);
111 _RETURN_DEST_NOT_NULL_TERMINATED(wsrc, sizeInWords);
112 }
113 _FILL_STRING(wsrc, sizeInWords, stringlen + 1);
114
115 if ( plocinfo->locinfo->locale_name[LC_CTYPE] == nullptr )
116 {
117 for ( p = wsrc ; *p ; p++ )
118 {
119 if ( (*p >= (wchar_t)L'a') && (*p <= (wchar_t)L'z') )
120 *p = *p - (L'a' - L'A');
121 }
122 return 0;
123 } /* C locale */
124
125
126 /* Inquire size of wdst string */
127 if ( (dstsize = __acrt_LCMapStringW(
128 plocinfo->locinfo->locale_name[LC_CTYPE],
130 wsrc,
131 -1,
132 nullptr,
133 0 )) == 0 )
134 {
135 errno = EILSEQ;
136 return errno;
137 }
138
139 if (sizeInWords < (size_t)dstsize)
140 {
141 _RESET_STRING(wsrc, sizeInWords);
142 _RETURN_BUFFER_TOO_SMALL(wsrc, sizeInWords);
143 }
144
145 /* Allocate space for wdst */
146 __crt_scoped_stack_ptr<wchar_t> const wdst(_malloca_crt_t(wchar_t, dstsize));
147 if (wdst.get() == nullptr)
148 {
149 errno = ENOMEM;
150 return errno;
151 }
152
153 /* Map wrc string to wide-character wdst string in alternate case */
155 plocinfo->locinfo->locale_name[LC_CTYPE],
157 wsrc,
158 -1,
159 wdst.get(),
160 dstsize ) != 0)
161 {
162 /* Copy wdst string to user string */
163 return wcscpy_s(wsrc, sizeInWords, wdst.get());
164 }
165 else
166 {
167 return errno = EILSEQ;
168 }
169}
170
172 wchar_t * wsrc,
173 size_t sizeInWords,
175 )
176{
177 _LocaleUpdate _loc_update(plocinfo);
178
179 return _wcsupr_s_l_stat(wsrc, sizeInWords, _loc_update.GetLocaleT());
180}
181
182
184 wchar_t * wsrc,
185 size_t sizeInWords
186 )
187{
188 return _wcsupr_s_l(wsrc, sizeInWords, nullptr);
189}
int __cdecl __acrt_LCMapStringW(LPCWSTR const locale_name, DWORD const map_flags, LPCWSTR const source, int source_count, LPWSTR const destination, int const destination_count)
#define EINVAL
Definition: acclib.h:90
#define ENOMEM
Definition: acclib.h:84
#define __cdecl
Definition: accygwin.h:79
#define _RETURN_DEST_NOT_NULL_TERMINATED(_String, _Size)
#define _FILL_STRING
#define _RETURN_BUFFER_TOO_SMALL(_String, _Size)
#define _RESET_STRING(_String, _Size)
#define _VALIDATE_RETURN(expr, errorcode, retexpr)
_wcsupr_s_l
_wcsupr
_wcsupr_l
GLint const GLchar GLint stringlen
Definition: glext.h:7232
GLfloat GLfloat p
Definition: glext.h:8902
#define LC_CTYPE
Definition: locale.h:19
#define _VALIDATE_RETURN_ERRCODE(expr, errorcode)
_locale_t plocinfo
Definition: ismbbyte.cpp:75
#define wcscpy_s(d, l, s)
Definition: utility.h:201
#define _Inout_updates_z_(s)
Definition: no_sal2.h:186
#define L(x)
Definition: ntvdm.h:50
#define errno
Definition: errno.h:18
#define EILSEQ
Definition: errno.h:109
size_t __cdecl wcsnlen(wchar_t const *const string, size_t const maximum_count)
Definition: strnlen.cpp:210
pthreadlocinfo locinfo
Definition: corecrt.h:23
#define wchar_t
Definition: wchar.h:102
int errno_t
Definition: corecrt.h:615
static errno_t __cdecl _wcsupr_s_l_stat(_Inout_updates_z_(sizeInWords) wchar_t *const wsrc, size_t const sizeInWords, _locale_t const plocinfo)
Definition: wcsupr.cpp:95
errno_t __cdecl _wcsupr_s(wchar_t *wsrc, size_t sizeInWords)
Definition: wcsupr.cpp:183
#define LCMAP_UPPERCASE
Definition: winnls.h:187