ReactOS 0.4.16-dev-1025-gd3456f5
mbslwr.cpp
Go to the documentation of this file.
1/***
2*mbslwr.c - Convert string lower case (MBCS)
3*
4* Copyright (c) Microsoft Corporation. All rights reserved.
5*
6*Purpose:
7* Convert string lower case (MBCS)
8*
9*******************************************************************************/
10#ifndef _MBCS
11 #error This file should only be compiled with _MBCS defined
12#endif
13
14#include <corecrt_internal.h>
17#include <locale.h>
18#include <string.h>
19
20#pragma warning(disable:__WARNING_POTENTIAL_BUFFER_OVERFLOW_NULLTERMINATED) // 26018
21
22/***
23* _mbslwr - Convert string lower case (MBCS)
24*
25*Purpose:
26* Convrts all the upper case characters in a string
27* to lower case in place. MBCS chars are handled
28* correctly.
29*
30*Entry:
31* unsigned char *string = pointer to string
32*
33*Exit:
34* Returns a pointer to the input string.
35* Returns nullptr on error.
36*
37*Exceptions:
38* Input parameters are validated. Refer to the validation section of the function.
39*
40*******************************************************************************/
41
43 unsigned char *string,
44 size_t sizeInBytes,
46 )
47{
48 size_t stringlen;
49
50 /* validation section */
51 _VALIDATE_RETURN_ERRCODE((string != nullptr && sizeInBytes > 0) || (string == nullptr && sizeInBytes == 0), EINVAL);
52
53 if (string == nullptr)
54 {
55 /* nothing to do */
56 return 0;
57 }
58
59 stringlen = strnlen((char *)string, sizeInBytes);
61 {
64 }
66
67 unsigned char *cp, *dst;
68 _LocaleUpdate _loc_update(plocinfo);
69
70 for (cp = string, dst = string; *cp != '\0'; ++cp)
71 {
72 if (_ismbblead_l(*cp, _loc_update.GetLocaleT()))
73 {
74
75
76 int retval;
77 unsigned char ret[4];
79 _loc_update.GetLocaleT(),
80 _loc_update.GetLocaleT()->mbcinfo->mblocalename,
82 (const char *)cp,
83 2,
84 (char *)ret,
85 2,
86 _loc_update.GetLocaleT()->mbcinfo->mbcodepage,
87 TRUE )) == 0 )
88 {
89 errno = EILSEQ;
91 return errno;
92 }
93
94 *(dst++) = ret[0];
95 ++cp;
96 if (retval > 1)
97 {
98 *(dst++) = ret[1];
99 }
100
101
102 }
103 else
104 {
105 /* single byte, macro version */
106 *(dst++) = (unsigned char) _mbbtolower_l(*cp, _loc_update.GetLocaleT());
107 }
108 }
109 /* null terminate the string */
110 *dst = '\0';
111
112 return 0;
113}
114
115errno_t (__cdecl _mbslwr_s)(
116 unsigned char *string,
118 )
119{
120 return _mbslwr_s_l(string, sizeInBytes, nullptr);
121}
122
123unsigned char * (__cdecl _mbslwr_l)(
124 unsigned char *string,
126 )
127{
128 return (_mbslwr_s_l(string, (string == nullptr ? 0 : (size_t)-1), plocinfo) == 0 ? string : nullptr);
129}
130
131unsigned char * (__cdecl _mbslwr)(
132 unsigned char *string
133 )
134{
135 return (_mbslwr_s_l(string, (string == nullptr ? 0 : (size_t)-1), nullptr) == 0 ? string : nullptr);
136}
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 _mbbtolower_l(_c, p)
#define _ismbblead_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 _mbslwr_l(unsigned char *string, _locale_t plocinfo)
Definition: mbslwr.cpp:123
size_t sizeInBytes
Definition: mbslwr.cpp:119
errno_t __cdecl _mbslwr_s_l(unsigned char *string, size_t sizeInBytes, _locale_t plocinfo)
Definition: mbslwr.cpp:42
unsigned char *__cdecl _mbslwr(unsigned char *string)
Definition: mbslwr.cpp:131
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_LOWERCASE
Definition: winnls.h:186