1 /***
2 *w_map.c - W version of LCMapString.
3 *
4 * Copyright (c) Microsoft Corporation. All rights reserved.
5 *
6 *Purpose:
7 * Wrapper for LCMapStringW.
8 *
9 *******************************************************************************/
10 #include <corecrt_internal.h>
11
12 /***
13 *int __cdecl __acrt_LCMapStringW - Get type information about a wide string.
14 *
15 *Purpose:
16 * Internal support function. Assumes info in wide string format.
17 *
18 *Entry:
19 * LPCWSTR LocaleName - locale context for the comparison.
20 * DWORD dwMapFlags - see NT\Chicago docs
21 * LPCWSTR lpSrcStr - pointer to string to be mapped
22 * int cchSrc - wide char (word) count of input string
23 * (including nullptr if any)
24 * (-1 if nullptr terminated)
25 * LPWSTR lpDestStr - pointer to memory to store mapping
26 * int cchDest - wide char (word) count of buffer (including nullptr)
27 *
28 * NOTE: if LCMAP_SORTKEY is specified, then cchDest refers to number
29 * of BYTES, not number of wide chars. The return string will be
30 * a series of bytes with a nullptr byte terminator.
31 *
32 *Exit:
33 * Success: if LCMAP_SORKEY:
34 * number of bytes written to lpDestStr (including nullptr byte
35 * terminator)
36 * else
37 * number of wide characters written to lpDestStr (including
38 * nullptr)
39 * Failure: 0
40 *
41 *Exceptions:
42 *
43 *******************************************************************************/
44
__acrt_LCMapStringW(LPCWSTR const locale_name,DWORD const map_flags,LPCWSTR const source,int source_count,LPWSTR const destination,int const destination_count)45 extern "C" int __cdecl __acrt_LCMapStringW(
46 LPCWSTR const locale_name,
47 DWORD const map_flags,
48 LPCWSTR const source,
49 int source_count,
50 LPWSTR const destination,
51 int const destination_count
52 )
53 {
54 // LCMapString will map past the null terminator. We must find the null
55 // terminator if it occurs in the string before source_count characters
56 // and cap the number of characters to be considered.
57 if (source_count > 0)
58 {
59 int const source_length = static_cast<int>(wcsnlen(source, source_count));
60
61 // Include the null terminator if the source string is terminated within
62 // the buffer.
63 if (source_length < source_count)
64 {
65 source_count = source_length + 1;
66 }
67 else
68 {
69 source_count = source_length;
70 }
71 }
72
73 return __acrt_LCMapStringEx(locale_name, map_flags, source, source_count, destination, destination_count, nullptr, nullptr, 0);
74 }
75