ReactOS 0.4.16-dev-852-gcfcc8d8
inittime.cpp
Go to the documentation of this file.
1//
2// inittime.cpp
3//
4// Copyright (c) Microsoft Corporation. All rights reserved.
5//
6// Functionality for initializing and destroying LC_TIME category data structures
7//
8#include <corecrt_internal.h>
9#include <locale.h>
10#include <stdlib.h>
11
12
13// Enclaves have no ability to create new locales.
14#ifndef _UCRT_ENCLAVE_BUILD
15
16_Success_(return != false)
17static bool __cdecl initialize_lc_time(
19 _In_ __crt_locale_data* const locale_data
21{
22 wchar_t const* const locale_name = locale_data->locale_name[LC_TIME];
23
24 __crt_locale_pointers locinfo = { locale_data, nullptr };
25
26 lc_time->_W_ww_locale_name = __acrt_copy_locale_name(locale_name);
27
28 int ret = 0;
29
30 // The days of the week. Note that the OS days are numbered 1-7, starting
31 // with Monday, whereas the lc_time days are numbered (indexed, really) 0-6
32 // starting with Sunday (thus the adjustment to the index in the loop).
33 for (unsigned int i = 0; i != 7; ++i)
34 {
35 unsigned int const result_index = (i + 1) % 7;
38
41 }
42
43 // The months of the year
44 for (unsigned int i = 0; i != 12; ++i)
45 {
48
51 }
52
55
58
63
67
68 return ret == 0;
69}
70
71
72
73_Success_(return != nullptr)
74static __crt_lc_time_data const* __cdecl get_or_create_lc_time(
75 _In_ __crt_locale_data* const locale_data
76 ) throw()
77{
78 // C Locale
79 if (!locale_data->locale_name[LC_TIME])
80 {
81 return &__lc_time_c;
82 }
83
84 // Non-C Locale
85 __crt_unique_heap_ptr<__crt_lc_time_data> lc_time = _calloc_crt_t(__crt_lc_time_data, 1);
86 if (!lc_time)
87 {
88 return nullptr;
89 }
90
91 if (!initialize_lc_time(lc_time.get(), locale_data))
92 {
94 return nullptr;
95 }
96
97 lc_time.get()->refcount = 1;
98
99 return lc_time.detach();
100}
101
102
103
105 __crt_locale_data* const locale_data
106 )
107{
108 __crt_lc_time_data const* const lc_time = get_or_create_lc_time(locale_data);
109 if (!lc_time)
110 {
111 return 1;
112 }
113
115 {
116 _ASSERTE(("lc_time_curr unexpectedly has no remaining references", 0));
117 }
118
119 locale_data->lc_time_curr = lc_time;
120 return 0;
121}
122
123#endif /* _UCRT_ENCLAVE_BUILD */
124
125
127 _Inout_updates_(array_count) void const** const array,
128 _In_ size_t const array_count
129 ) throw()
130{
131 for (void const* const* it = array; it != array + array_count; ++it)
132 {
133 _free_crt(const_cast<void*>(*it));
134 }
135}
136
137
138
139template <typename T, size_t N>
140static void __cdecl free_crt_array(_Inout_ T* (&array)[N]) throw()
141{
142 return free_crt_array_internal(const_cast<void const**>(reinterpret_cast<void const* const*>(array)), N);
143}
144
145
146
149 )
150{
151 if (!lc_time)
152 {
153 return;
154 }
155
156 free_crt_array(lc_time->wday_abbr);
157 free_crt_array(lc_time->wday);
158 free_crt_array(lc_time->month_abbr);
159 free_crt_array(lc_time->month);
160 free_crt_array(lc_time->ampm);
161
162 _free_crt(lc_time->ww_sdatefmt);
163 _free_crt(lc_time->ww_ldatefmt);
164 _free_crt(lc_time->ww_timefmt);
165
166 free_crt_array(lc_time->_W_wday_abbr);
167 free_crt_array(lc_time->_W_wday);
168 free_crt_array(lc_time->_W_month_abbr);
169 free_crt_array(lc_time->_W_month);
170 free_crt_array(lc_time->_W_ampm);
171
172 _free_crt(lc_time->_W_ww_sdatefmt);
173 _free_crt(lc_time->_W_ww_ldatefmt);
174 _free_crt(lc_time->_W_ww_timefmt);
175
176 _free_crt(lc_time->_W_ww_locale_name);
177}
#define N
Definition: crc32.c:57
#define __cdecl
Definition: accygwin.h:79
#define LC_WSTR_TYPE
#define LC_INT_TYPE
__crt_lc_time_data const __lc_time_c
Definition: nlsdata.cpp:33
int __cdecl __acrt_GetLocaleInfoA(_In_opt_ _locale_t _Locale, _In_ int _LCType, _In_ LPCWSTR _LocaleName, _In_ LCTYPE _FieldType, _Out_ void *_Address)
#define LC_STR_TYPE
long __cdecl __acrt_locale_release_lc_time_reference(_In_opt_ __crt_lc_time_data const *lc_time)
#define _ASSERTE(expr)
Definition: crtdbg.h:114
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define LC_TIME
Definition: locale.h:22
_In_ __crt_locale_data *const locale_data throw()
Definition: inittime.cpp:20
static void __cdecl free_crt_array(_Inout_ T *(&array)[N])
Definition: inittime.cpp:140
int __cdecl __acrt_locale_initialize_time(__crt_locale_data *const locale_data)
Definition: inittime.cpp:104
void __cdecl __acrt_locale_free_time(__crt_lc_time_data *const lc_time)
Definition: inittime.cpp:147
static void __cdecl free_crt_array_internal(_Inout_updates_(array_count) void const **const array, _In_ size_t const array_count)
Definition: inittime.cpp:126
#define _free_crt
#define T
Definition: mbstring.h:31
#define _Inout_updates_(s)
Definition: no_sal2.h:182
#define _Inout_
Definition: no_sal2.h:162
#define _Success_(c)
Definition: no_sal2.h:84
#define _In_
Definition: no_sal2.h:158
else locinfo
Definition: scanf.h:159
__crt_lc_time_data const * lc_time_curr
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t _Inout_ size_t __crt_lc_time_data const * lc_time
Definition: wcsftime.cpp:385
int ret
#define LOCALE_SDAYNAME1
Definition: winnls.h:79
#define LOCALE_SLONGDATE
Definition: winnls.h:63
#define LOCALE_S1159
Definition: winnls.h:73
#define LOCALE_SSHORTDATE
Definition: winnls.h:62
#define LOCALE_SMONTHNAME1
Definition: winnls.h:93
#define LOCALE_SABBREVMONTHNAME1
Definition: winnls.h:106
#define LOCALE_STIMEFORMAT
Definition: winnls.h:64
#define LOCALE_SABBREVDAYNAME1
Definition: winnls.h:86
#define LOCALE_S2359
Definition: winnls.h:74
#define LOCALE_ICALENDARTYPE
Definition: winnls.h:75
LPWSTR __cdecl __acrt_copy_locale_name(LPCWSTR localeName)
#define const
Definition: zconf.h:233