ReactOS 0.4.16-dev-959-g2ec3a19
strxfrm.cpp File Reference
#include <corecrt_internal.h>
#include <ctype.h>
#include <locale.h>
#include <string.h>
Include dependency graph for strxfrm.cpp:

Go to the source code of this file.

Functions

size_t __cdecl _strxfrm_l (char *_string1, const char *_string2, size_t _count, _locale_t plocinfo)
 
size_t __cdecl strxfrm (char *_string1, const char *_string2, size_t _count)
 

Function Documentation

◆ _strxfrm_l()

size_t __cdecl _strxfrm_l ( char _string1,
const char _string2,
size_t  _count,
_locale_t  plocinfo 
)

Definition at line 55 of file strxfrm.cpp.

61{
62 int dstlen;
63 size_t retval = INT_MAX; /* NON-ANSI: default if OM or API error */
64 _LocaleUpdate _loc_update(plocinfo);
65
66 /* validation section */
68 _VALIDATE_RETURN(_string1 != nullptr || _count == 0, EINVAL, INT_MAX);
69 _VALIDATE_RETURN(_string2 != nullptr, EINVAL, INT_MAX);
70
71 /* pre-init output in case of error */
72 if(_string1!=nullptr && _count>0)
73 {
74 *_string1='\0';
75 }
76
77 if ( (_loc_update.GetLocaleT()->locinfo->locale_name[LC_COLLATE] == nullptr) &&
78 (_loc_update.GetLocaleT()->locinfo->lc_collate_cp == CP_ACP) )
79 {
81 strncpy(_string1, _string2, _count);
83 return strlen(_string2);
84 }
85
86 /* Inquire size of dst string in BYTES */
87 if ( 0 == (dstlen = __acrt_LCMapStringA(
88 _loc_update.GetLocaleT(),
89 _loc_update.GetLocaleT()->locinfo->locale_name[LC_COLLATE],
91 _string2,
92 -1,
93 nullptr,
94 0,
95 _loc_update.GetLocaleT()->locinfo->lc_collate_cp,
96 TRUE )) )
97 {
98 errno = EILSEQ;
99 return INT_MAX;
100 }
101
103
104 /* if not enough room, return amount needed */
105 if ( retval > _count )
106 {
107 if (_string1 != nullptr && _count > 0)
108 {
109 *_string1 = '\0';
110 errno = ERANGE;
111 }
112 /* the return value is the string length (without the terminating 0) */
113 retval--;
114 return retval;
115 }
116
117 /* Map src string to dst string */
118 if ( 0 == __acrt_LCMapStringA(
119 _loc_update.GetLocaleT(),
120 _loc_update.GetLocaleT()->locinfo->locale_name[LC_COLLATE],
122 _string2,
123 -1,
124 _string1,
125 (int)_count,
126 _loc_update.GetLocaleT()->locinfo->lc_collate_cp,
127 TRUE ) )
128 {
129 errno = EILSEQ;
130 return INT_MAX;
131 }
132 /* the return value is the string length (without the terminating 0) */
133 retval--;
134
135 return retval;
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
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define ERANGE
Definition: acclib.h:92
#define _VALIDATE_RETURN(expr, errorcode, retexpr)
#define TRUE
Definition: types.h:120
#define CP_ACP
Definition: compat.h:109
__kernel_size_t size_t
Definition: linux.h:237
#define LC_COLLATE
Definition: locale.h:18
#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
static DWORD dstlen
Definition: directory.c:51
#define errno
Definition: errno.h:18
#define EILSEQ
Definition: errno.h:109
strncpy
Definition: string.h:335
int retval
Definition: wcstombs.cpp:91
#define LCMAP_SORTKEY
Definition: winnls.h:188

Referenced by strxfrm().

◆ strxfrm()

size_t __cdecl strxfrm ( char _string1,
const char _string2,
size_t  _count 
)

Definition at line 138 of file strxfrm.cpp.

143{
144
145 return _strxfrm_l(_string1, _string2, _count, nullptr);
146
147}
size_t __cdecl _strxfrm_l(char *_string1, const char *_string2, size_t _count, _locale_t plocinfo)
Definition: strxfrm.cpp:55