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

Go to the source code of this file.

Functions

size_t __cdecl _wcsxfrm_l (wchar_t *_string1, const wchar_t *_string2, size_t _count, _locale_t plocinfo)
 
size_t __cdecl wcsxfrm (wchar_t *_string1, const wchar_t *_string2, size_t _count)
 

Function Documentation

◆ _wcsxfrm_l()

size_t __cdecl _wcsxfrm_l ( wchar_t _string1,
const wchar_t _string2,
size_t  _count,
_locale_t  plocinfo 
)

Definition at line 51 of file wcsxfrm.cpp.

57{
58 int size = INT_MAX;
59
60 /* validation section */
62 _VALIDATE_RETURN(_string1 != nullptr || _count == 0, EINVAL, INT_MAX);
63 _VALIDATE_RETURN(_string2 != nullptr, EINVAL, INT_MAX);
64
65 _LocaleUpdate _loc_update(plocinfo);
66
67 if ( _loc_update.GetLocaleT()->locinfo->locale_name[LC_COLLATE] == nullptr )
68 {
70 wcsncpy(_string1, _string2, _count);
72 return wcslen(_string2);
73 }
74
75 if ( 0 == (size = __acrt_LCMapStringW(
76 _loc_update.GetLocaleT()->locinfo->locale_name[LC_COLLATE],
78 _string2,
79 -1,
80 nullptr,
81 0 )) )
82 {
83 errno = EILSEQ;
84 size = INT_MAX;
85 } else
86 {
87 if ( size <= (int)_count)
88 {
89 if ( 0 == (size = __acrt_LCMapStringW(
90 _loc_update.GetLocaleT()->locinfo->locale_name[LC_COLLATE],
92 _string2,
93 -1,
94 (wchar_t *)_string1,
95 (int)_count )) )
96 {
97 errno = EILSEQ;
98 size = INT_MAX; /* default error */
99 } else
100 {
101 // Note that the size that LCMapStringW returns for
102 // LCMAP_SORTKEY is number of bytes needed. That's why it
103 // is safe to convert the buffer to wide char from end.
104 _count = size--;
105 for (;_count-- > 0;)
106 {
107#pragma warning(suppress:__WARNING_DEREF_NULL_PTR __WARNING_POTENTIAL_BUFFER_OVERFLOW_HIGH_PRIORITY) // 6011 Dereferencing NULL pointer '_string1' 26015 Potential overflow using expression '_string1[_count]'
108 _string1[_count] = (wchar_t)((unsigned char *)_string1)[_count];
109 }
110 }
111 }
112 else
113 {
114 if (_string1 != nullptr && _count > 0)
115 {
116 *_string1 = '\0';
117 errno = ERANGE;
118 }
119 size--;
120 }
121 }
122
123 return (size_t)size;
124}
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 ERANGE
Definition: acclib.h:92
#define _VALIDATE_RETURN(expr, errorcode, retexpr)
wcsncpy
GLsizeiptr size
Definition: glext.h:5919
#define LC_COLLATE
Definition: locale.h:18
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define _BEGIN_SECURE_CRT_DEPRECATION_DISABLE
#define _END_SECURE_CRT_DEPRECATION_DISABLE
#define INT_MAX
Definition: intsafe.h:150
_locale_t plocinfo
Definition: ismbbyte.cpp:75
#define errno
Definition: errno.h:18
#define EILSEQ
Definition: errno.h:109
#define wchar_t
Definition: wchar.h:102
#define LCMAP_SORTKEY
Definition: winnls.h:188

Referenced by wcsxfrm().

◆ wcsxfrm()

size_t __cdecl wcsxfrm ( wchar_t _string1,
const wchar_t _string2,
size_t  _count 
)

Definition at line 126 of file wcsxfrm.cpp.

131{
132
133 return _wcsxfrm_l(_string1, _string2, _count, nullptr);
134}
size_t __cdecl _wcsxfrm_l(wchar_t *_string1, const wchar_t *_string2, size_t _count, _locale_t plocinfo)
Definition: wcsxfrm.cpp:51