ReactOS 0.4.16-dev-835-gd769f56
GetLocaleInfoA.cpp File Reference
#include <corecrt_internal.h>
Include dependency graph for GetLocaleInfoA.cpp:

Go to the source code of this file.

Functions

 _Success_ (return > 0) static int __cdecl InternalGetLocaleInfoA(_locale_t const locale
 
PCWSTR const LCTYPE const _Out_writes_z_ (result_size) char *const result
 
 if (buffer_size==0) return 0
 
__crt_scoped_stack_ptr< wchar_t > const buffer (_malloca_crt_t(wchar_t, buffer_size))
 
 if (buffer.get()==nullptr) return 0
 
 if (__acrt_GetLocaleInfoEx(locale_name, locale_type, buffer.get(), buffer_size)==0) return 0
 
return __acrt_WideCharToMultiByte (code_page, 0, buffer.get(), -1, result_size !=0 ? result :nullptr, result_size, nullptr, nullptr)
 
int __cdecl __acrt_GetLocaleInfoA (_locale_t const locale, int const lc_type, wchar_t const *const locale_name, LCTYPE const locale_type, void *const void_result)
 

Variables

PCWSTR const locale_name
 
PCWSTR const LCTYPE const locale_type
 
PCWSTR const LCTYPE const int const result_size
 
int const code_page = locale_update.GetLocaleT()->locinfo->_public._locale_lc_codepage
 
int const buffer_size = __acrt_GetLocaleInfoEx(locale_name, locale_type, nullptr, 0)
 

Function Documentation

◆ __acrt_GetLocaleInfoA()

int __cdecl __acrt_GetLocaleInfoA ( _locale_t const  locale,
int const  lc_type,
wchar_t const *const  locale_name,
LCTYPE const  locale_type,
void *const  void_result 
)

Definition at line 71 of file GetLocaleInfoA.cpp.

78{
79 *static_cast<void**>(void_result) = nullptr;
80
81 if (lc_type == LC_STR_TYPE)
82 {
83 char** const char_result = static_cast<char**>(void_result);
84
85 int const local_buffer_size = 128;
86 char local_buffer[local_buffer_size];
87
88 int const local_length = InternalGetLocaleInfoA(
89 locale, locale_name, locale_type, local_buffer, local_buffer_size);
90
91 if (local_length != 0)
92 {
93 *char_result = _calloc_crt_t(char, local_length).detach();
94 if (*char_result == nullptr)
95 return -1;
96
97 _ERRCHECK(strncpy_s(*char_result, local_length, local_buffer, local_length - 1));
98 return 0;
99 }
100
102 return -1;
103
104 // If the buffer size was too small, compute the required size and use a
105 // dynamically allocated buffer:
106 int const required_length = InternalGetLocaleInfoA(
107 locale, locale_name, locale_type, nullptr, 0);
108
109 if (required_length == 0)
110 return -1;
111
112 __crt_unique_heap_ptr<char> dynamic_buffer(_calloc_crt_t(char, required_length));
113 if (dynamic_buffer.get() == nullptr)
114 return -1;
115
116 int const actual_length = InternalGetLocaleInfoA(
117 locale, locale_name, locale_type, dynamic_buffer.get(), required_length);
118
119 if (actual_length == 0)
120 return -1;
121
122 *char_result = dynamic_buffer.detach();
123 return 0;
124 }
125 else if (lc_type == LC_WSTR_TYPE)
126 {
127 wchar_t** const wchar_result = static_cast<wchar_t**>(void_result);
128
129 int const required_length = __acrt_GetLocaleInfoEx(locale_name, locale_type, nullptr, 0);
130 if (required_length == 0)
131 return -1;
132
133 __crt_unique_heap_ptr<wchar_t> dynamic_buffer(_calloc_crt_t(wchar_t, required_length));
134 if (dynamic_buffer.get() == nullptr)
135 return -1;
136
137 int const actual_length = __acrt_GetLocaleInfoEx(
138 locale_name, locale_type, dynamic_buffer.get(), required_length);
139
140 if (actual_length == 0)
141 return -1;
142
143 *wchar_result = dynamic_buffer.detach();
144 return 0;
145 }
146 else if (lc_type == LC_INT_TYPE)
147 {
148 unsigned char* const uchar_result = static_cast<unsigned char*>(void_result);
149
150 DWORD value = 0;
151 int const actual_length = __acrt_GetLocaleInfoEx(
153 locale_type | LOCALE_RETURN_NUMBER,
154 reinterpret_cast<wchar_t*>(&value),
155 sizeof(value) / sizeof(wchar_t));
156
157 if (actual_length == 0)
158 return -1;
159
160 *uchar_result = static_cast<unsigned char>(value);
161 return 0;
162 }
163
164 return -1;
165}
PCWSTR const LCTYPE const locale_type
Definition: _locale.h:75
int WINAPI __acrt_GetLocaleInfoEx(_In_opt_ LPCWSTR locale_name, _In_ LCTYPE lc_type, _Out_writes_opt_(data_count) LPWSTR data, _In_ int data_count)
#define LC_WSTR_TYPE
#define LC_INT_TYPE
#define _ERRCHECK(e)
#define LC_STR_TYPE
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
unsigned long DWORD
Definition: ntddk_ex.h:95
strncpy_s
Definition: string.h:335
Definition: pdh_main.c:94
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

◆ __acrt_WideCharToMultiByte()

◆ _Out_writes_z_()

PCWSTR const LCTYPE const _Out_writes_z_ ( result_size  ) const

◆ _Success_()

_Success_ ( return  ,
 
) const

◆ buffer()

__crt_scoped_stack_ptr< wchar_t > const buffer ( _malloca_crt_t(wchar_t, buffer_size )

◆ if() [1/3]

◆ if() [2/3]

if ( buffer.  get() = =nullptr)

◆ if() [3/3]

if ( buffer_size  = =0)

Variable Documentation

◆ buffer_size

Definition at line 26 of file GetLocaleInfoA.cpp.

◆ code_page

int const code_page = locale_update.GetLocaleT()->locinfo->_public._locale_lc_codepage

Definition at line 24 of file GetLocaleInfoA.cpp.

◆ locale_name

Definition at line 16 of file GetLocaleInfoA.cpp.

◆ locale_type

PCWSTR const LCTYPE const locale_type

Definition at line 17 of file GetLocaleInfoA.cpp.

Referenced by __acrt_GetLocaleInfoA().

◆ result_size

Initial value:
{
_LocaleUpdate locale_update(locale)

Definition at line 19 of file GetLocaleInfoA.cpp.

Referenced by test_persistserialized().