ReactOS 0.4.16-dev-716-g2b2bdab
strftime.cpp File Reference
#include <corecrt_internal_time.h>
#include <locale.h>
Include dependency graph for strftime.cpp:

Go to the source code of this file.

Functions

char *__cdecl _Getdays_l (_locale_t const locale)
 
char *__cdecl _Getdays ()
 
char *__cdecl _Getmonths_l (_locale_t const locale)
 
char *__cdecl _Getmonths ()
 
void *__cdecl _W_Gettnames ()
 
void *__cdecl _Gettnames ()
 
 _Success_ (return > 0) extern "C" size_t __cdecl _Strftime_l(_Out_writes_z_(maxsize) char *const string
 
 if (cvt1 !=0)
 
__crt_unique_heap_ptr< wchar_t > const wstring (_malloc_crt_t(wchar_t, maxsize))
 
 if (wstring.get()==nullptr)
 
 if (wcsftime_result==0)
 
__crt_no_alloc_win32_buffer< charcopy_back (string, maxsize)
 
 if (cvt2 !=0)
 
return copy_back size ()
 
size_t __cdecl _Strftime (char *const string, size_t const max_size, char const *const format, tm const *const timeptr, void *const lc_time_arg)
 
size_t __cdecl _strftime_l (char *const string, size_t const max_size, char const *const format, tm const *const timeptr, _locale_t const locale)
 
size_t __cdecl strftime (char *const string, size_t const max_size, char const *const format, tm const *const timeptr)
 

Variables

_In_ size_t const maxsize
 
_In_ size_t const _In_z_ const char *const format
 
_In_ size_t const _In_z_ const char *const _In_ const tm *const timeptr
 
_In_ size_t const _In_z_ const char *const _In_ const tm *const _In_ void *const lc_time_arg
 
_In_ size_t const _In_z_ const char *const _In_ const tm *const _In_ void *const _In_opt_ _locale_t const locale
 
unsigned int const lc_time_cp = locale_update.GetLocaleT()->locinfo->lc_time_cp
 
string = '\0'
 
__crt_internal_win32_buffer< wchar_twformat
 
errno_t const cvt1 = __acrt_mbs_to_wcs_cp(format, wformat, lc_time_cp)
 
size_t const wcsftime_result = _Wcsftime_l(wstring.get(), maxsize, wformat.data(), timeptr, lc_time_arg, locale)
 
errno_t const cvt2 = __acrt_wcs_to_mbs_cp(wstring.get(), copy_back, lc_time_cp)
 

Function Documentation

◆ _Getdays()

char *__cdecl _Getdays ( void  )

Definition at line 48 of file strftime.cpp.

49{
50 return _Getdays_l(nullptr);
51}
char *__cdecl _Getdays_l(_locale_t const locale)
Definition: strftime.cpp:17

◆ _Getdays_l()

char *__cdecl _Getdays_l ( _locale_t const  locale)

Definition at line 17 of file strftime.cpp.

18{
19 _LocaleUpdate locale_update(locale);
20 __crt_lc_time_data const* const time_data = locale_update.GetLocaleT()->locinfo->lc_time_curr;
21
22 size_t length = 0;
23 for (size_t n = 0; n < 7; ++n)
24 {
25 length += strlen(time_data->wday_abbr[n]) + strlen(time_data->wday[n]) + 2;
26 }
27
28 __crt_unique_heap_ptr<char> buffer(_malloc_crt_t(char, length + 1));
29 if (buffer.get() == nullptr)
30 return nullptr;
31
32
33 char* it = buffer.get();
34 for (size_t n = 0; n < 7; ++n)
35 {
36 *it++ = ':';
37 _ERRCHECK(strcpy_s(it, (length + 1) - (it - buffer.get()), time_data->wday_abbr[n]));
38 it += strlen(it);
39 *it++ = ':';
40 _ERRCHECK(strcpy_s(it, (length + 1) - (it - buffer.get()), time_data->wday[n]));
41 it += strlen(it);
42 }
43 *it++ = '\0';
44
45 return buffer.detach();
46}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
Definition: _locale.h:75
#define _ERRCHECK(e)
GLdouble n
Definition: glext.h:7729
GLuint buffer
Definition: glext.h:5915
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
#define strcpy_s(d, l, s)
Definition: utility.h:200

Referenced by _Getdays().

◆ _Getmonths()

char *__cdecl _Getmonths ( void  )

Definition at line 87 of file strftime.cpp.

88{
89 return _Getmonths_l(nullptr);
90}
char *__cdecl _Getmonths_l(_locale_t const locale)
Definition: strftime.cpp:55

◆ _Getmonths_l()

char *__cdecl _Getmonths_l ( _locale_t const  locale)

Definition at line 55 of file strftime.cpp.

56{
57 _LocaleUpdate locale_update(locale);
58 __crt_lc_time_data const* time_data = locale_update.GetLocaleT()->locinfo->lc_time_curr;
59
60 size_t length = 0;
61 for (size_t n = 0; n < 12; ++n)
62 {
63 length += strlen(time_data->month_abbr[n]) + strlen(time_data->month[n]) + 2;
64 }
65
66 __crt_unique_heap_ptr<char> buffer(_malloc_crt_t(char, length + 1));
67 if (buffer.get() == nullptr)
68 return nullptr;
69
70 char* it = buffer.get();
71 for (size_t n = 0; n < 12; ++n)
72 {
73 *it++ = ':';
74 _ERRCHECK(strcpy_s(it, (length + 1) - (it - buffer.get()), time_data->month_abbr[n]));
75 it += strlen(it);
76 *it++ = ':';
77 _ERRCHECK(strcpy_s(it, (length + 1) - (it - buffer.get()), time_data->month[n]));
78 it += strlen(it);
79 }
80 *it++ = '\0';
81
82 return buffer.detach();
83}

Referenced by _Getmonths().

◆ _Gettnames()

void *__cdecl _Gettnames ( void  )

Definition at line 94 of file strftime.cpp.

95{
96 return _W_Gettnames();
97}
void *__cdecl _W_Gettnames()
Definition: wcsftime.cpp:83

Referenced by test__Gettnames().

◆ _Strftime()

size_t __cdecl _Strftime ( char *const  string,
size_t const  max_size,
char const *const  format,
tm const *const  timeptr,
void *const  lc_time_arg 
)

Definition at line 170 of file strftime.cpp.

177{
178 return _Strftime_l(string, max_size, format, timeptr, lc_time_arg, nullptr);
179}
static INT max_size
Definition: history.c:51
_In_ size_t const _In_z_ const char *const _In_ const tm *const timeptr
Definition: strftime.cpp:122
_In_ size_t const _In_z_ const char *const _In_ const tm *const _In_ void *const lc_time_arg
Definition: strftime.cpp:123
Definition: format.c:58

◆ _strftime_l()

size_t __cdecl _strftime_l ( char *const  string,
size_t const  max_size,
char const *const  format,
tm const *const  timeptr,
_locale_t const  locale 
)

Definition at line 181 of file strftime.cpp.

188{
189 return _Strftime_l(string, max_size, format, timeptr, nullptr, locale);
190}

◆ _Success_()

_Success_ ( return  ,
 
) const

◆ _W_Gettnames()

void *__cdecl _W_Gettnames ( )

Definition at line 83 of file wcsftime.cpp.

84{
85 _LocaleUpdate locale_update(nullptr);
86 __crt_lc_time_data const* const src = locale_update.GetLocaleT()->locinfo->lc_time_curr;
87
88
89
90 #define PROCESS_STRING(STR, CHAR, CPY, LEN) \
91 while (bytes % sizeof(CHAR) != 0) \
92 { \
93 ++bytes; \
94 } \
95 if (phase == 1) \
96 { \
97 dest->STR = ((CHAR *) dest) + bytes / sizeof(CHAR); \
98 _ERRCHECK(CPY(dest->STR, (total_bytes - bytes) / sizeof(CHAR), src->STR)); \
99 } \
100 bytes += (LEN(src->STR) + 1) * sizeof(CHAR);
101
102 #define PROCESS_NARROW_STRING(STR) \
103 PROCESS_STRING(STR, char, strcpy_s, strlen)
104
105 #define PROCESS_WIDE_STRING(STR) \
106 PROCESS_STRING(STR, wchar_t, wcscpy_s, wcslen)
107
108 #define PROCESS_NARROW_ARRAY(ARR) \
109 for (size_t idx = 0; idx < _countof(src->ARR); ++idx) \
110 { \
111 PROCESS_NARROW_STRING(ARR[idx]) \
112 }
113
114 #define PROCESS_WIDE_ARRAY(ARR) \
115 for (size_t idx = 0; idx < _countof(src->ARR); ++idx) \
116 { \
117 PROCESS_WIDE_STRING(ARR[idx]) \
118 }
119
120
121 size_t total_bytes = 0;
122 size_t bytes = sizeof(__crt_lc_time_data);
123
124 __crt_lc_time_data* dest = nullptr;
125 for (int phase = 0; phase < 2; ++phase)
126 {
127 if (phase == 1)
128 {
129 dest = static_cast<__crt_lc_time_data*>(_malloc_crt(bytes));
130
131 if (!dest) {
132 return nullptr;
133 }
134
135 memset(dest, 0, bytes);
136
137 total_bytes = bytes;
138
139 bytes = sizeof(__crt_lc_time_data);
140 }
141
142 PROCESS_NARROW_ARRAY(wday_abbr)
144 PROCESS_NARROW_ARRAY(month_abbr)
147 PROCESS_NARROW_STRING(ww_sdatefmt)
148 PROCESS_NARROW_STRING(ww_ldatefmt)
149 PROCESS_NARROW_STRING(ww_timefmt)
150
151 if (phase == 1)
152 {
153 dest->ww_caltype = src->ww_caltype;
154 dest->refcount = 0;
155 }
156
157 PROCESS_WIDE_ARRAY(_W_wday_abbr)
158 PROCESS_WIDE_ARRAY(_W_wday)
159 PROCESS_WIDE_ARRAY(_W_month_abbr)
160 PROCESS_WIDE_ARRAY(_W_month)
161 PROCESS_WIDE_ARRAY(_W_ampm)
162 PROCESS_WIDE_STRING(_W_ww_sdatefmt)
163 PROCESS_WIDE_STRING(_W_ww_ldatefmt)
164 PROCESS_WIDE_STRING(_W_ww_timefmt)
165 PROCESS_WIDE_STRING(_W_ww_locale_name)
166 }
167
168 return dest;
169}
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
static const WCHAR month[12][4]
Definition: session.c:2150
GLenum src
Definition: glext.h:6340
#define _malloc_crt
static char * dest
Definition: rtl.c:135
#define memset(x, y, z)
Definition: compat.h:39
#define PROCESS_NARROW_STRING(STR)
#define PROCESS_NARROW_ARRAY(ARR)
#define PROCESS_WIDE_STRING(STR)
#define PROCESS_WIDE_ARRAY(ARR)

Referenced by _Gettnames().

◆ copy_back()

__crt_no_alloc_win32_buffer< char > copy_back ( string  ,
maxsize   
)

◆ if() [1/4]

if ( cvt1 = 0)

Definition at line 141 of file strftime.cpp.

141 {
142 return 0;
143 }

◆ if() [2/4]

if ( cvt2 = 0)

Definition at line 163 of file strftime.cpp.

163 {
164 return 0;
165 }

◆ if() [3/4]

if ( wcsftime_result  = = 0)

Definition at line 155 of file strftime.cpp.

156 {
157 return 0;
158 }

◆ if() [4/4]

if ( wstring.  get() = nullptr)

Definition at line 148 of file strftime.cpp.

149 {
150 // malloc should set the errno, if any
151 return 0;
152 }

◆ size()

◆ strftime()

size_t __cdecl strftime ( char *const  string,
size_t const  max_size,
char const *const  format,
tm const *const  timeptr 
)

Definition at line 191 of file strftime.cpp.

197{
198 return _Strftime_l(string, max_size, format, timeptr, nullptr, nullptr);
199}

◆ wstring()

__crt_unique_heap_ptr< wchar_t > const wstring ( _malloc_crt_t(wchar_t, maxsize )

Referenced by __do_widen(), LocaleTest::_time_put_get(), add_lv_column(), BtrfsDeviceAdd::AddDevice(), AsciiToUnicode(), BtrfsBalance::BalanceOptsDlgProc(), basic_tests(), BitsetTest::bitset1(), BtrfsRecv::cmd_chmod(), BtrfsRecv::cmd_chown(), BtrfsRecv::cmd_clone(), BtrfsRecv::cmd_link(), BtrfsRecv::cmd_mkfile(), BtrfsRecv::cmd_removexattr(), BtrfsRecv::cmd_rename(), BtrfsRecv::cmd_rmdir(), BtrfsRecv::cmd_setxattr(), BtrfsRecv::cmd_snapshot(), BtrfsRecv::cmd_truncate(), BtrfsRecv::cmd_unlink(), BtrfsRecv::cmd_utimes(), BtrfsRecv::cmd_write(), LocaleTest::collate_facet(), create_snapshot(), create_snapshot2(), create_subvol(), delete_directory(), BtrfsVolPropSheet::DeviceDlgProc(), BtrfsDeviceResize::DeviceResizeDlgProc(), BtrfsChangeDriveLetter::DlgProc(), BtrfsChangeDriveLetter::do_change(), _Messages::do_get(), BtrfsDeviceResize::do_resize(), BtrfsPropSheet::do_search(), collate< wchar_t >::do_transform(), CWineTest::DoListCommand(), error_message(), find_devices(), format_insert(), format_message(), format_ntstatus(), format_size(), BtrfsVolPropSheet::FormatUsage(), get_mountdev_name(), DriveVolume::GetClusterInfo(), GetDefaultTitle(), GetDefragTitle(), CWineTest::GetNextFile(), Defragment::GetStatusString(), CodecvtTest::in_out_test(), BtrfsPropSheet::init_propsheet(), InitDialog(), BtrfsContextMenu::Initialize(), BtrfsContextMenu::InvokeCommand(), load_string(), MainDialogProc(), MoveConstructorTest::movable_declaration(), DriveVolume::MoveFileDumb(), BtrfsPropSheet::open_as_admin(), BtrfsBalance::PauseBalance(), BtrfsDeviceAdd::populate_device_tree(), PropSheetDlgProc(), BtrfsContextMenu::QueryContextMenu(), BtrfsRecv::recv_thread(), BtrfsRecv::RecvProgressDlgProc(), BtrfsContextMenu::reflink_copy(), reflink_copy2(), ReflinkCopyW(), BtrfsBalance::RefreshBalanceDlg(), BtrfsVolPropSheet::RefreshDevList(), BtrfsScrub::RefreshScrubDlg(), BtrfsVolPropSheet::RefreshUsage(), reg_context_menu_handler(), reg_icon_overlay(), reg_prop_sheet_handler(), register_clsid(), BtrfsVolPropSheet::ResetStats(), ResetStatsW(), DriveVolume::ScanDirectory(), SendSubvolW(), BtrfsPropSheet::set_size_on_disk(), BtrfsVolPropSheet::ShowChangeDriveLetter(), ShowPropSheetW(), BtrfsVolPropSheet::ShowScrub(), CodecvtTest::special_encodings(), Defragment::Start(), BtrfsBalance::StartBalance(), BtrfsSend::StartSend(), BtrfsVolPropSheet::StatsDlgProc(), BtrfsBalance::StopBalance(), string_error::string_error(), StringTest::template_wexpression(), test_ime_wnd_proc(), test_ImmGetCompositionString(), BtrfsSend::Thread(), unreg_context_menu_handler(), unreg_icon_overlay(), unreg_prop_sheet_handler(), unregister_clsid(), CJournaledTestList::UnserializeFromBuffer(), BtrfsPropSheet::update_size_details_dialog(), UpdateDefragInfo(), BtrfsScrub::UpdateTextBox(), BtrfsVolPropSheet::UsageDlgProc(), and utf8_to_utf16().

Variable Documentation

◆ cvt1

◆ cvt2

◆ format

Definition at line 121 of file strftime.cpp.

◆ lc_time_arg

Definition at line 123 of file strftime.cpp.

Referenced by _Strftime().

◆ lc_time_cp

unsigned int const lc_time_cp = locale_update.GetLocaleT()->locinfo->lc_time_cp

Definition at line 128 of file strftime.cpp.

◆ locale

Initial value:
{
_LocaleUpdate locale_update(locale)

Definition at line 124 of file strftime.cpp.

◆ maxsize

◆ string

* string = '\0'

Definition at line 132 of file strftime.cpp.

◆ timeptr

Definition at line 122 of file strftime.cpp.

Referenced by _Strftime(), _strftime_l(), and strftime().

◆ wcsftime_result

Definition at line 154 of file strftime.cpp.

◆ wformat

Definition at line 137 of file strftime.cpp.