ReactOS 0.4.16-dev-959-g2ec3a19
asctime.cpp File Reference
Include dependency graph for asctime.cpp:

Go to the source code of this file.

Macros

#define _ASCBUFSIZE   26
 

Functions

template<typename Character >
static Character *__cdecl common_asctime_s_write_value (_Out_writes_(2) Character *p, int const value, bool const zero_fill) throw ()
 
template<typename Character >
 _Success_ (return==0) static errno_t __cdecl common_asctime_s(_Out_writes_z_(size_in_chars) _Post_readable_size_(_ASCBUFSIZE) Character *const buffer
 
 _In_range_ (>=, _ASCBUFSIZE) size_t const size_in_chars
 
tm const *const tm_value throw ()
 
errno_t __cdecl asctime_s (char *const buffer, size_t const size_in_chars, tm const *const tm_value)
 
errno_t __cdecl _wasctime_s (wchar_t *const buffer, size_t const size_in_chars, tm const *const tm_value)
 
static char ** common_asctime_get_ptd_buffer (char) throw ()
 
static wchar_t ** common_asctime_get_ptd_buffer (wchar_t) throw ()
 
template<typename Character >
 _Success_ (return !=0) _Ret_writes_z_(26) static Character *__cdecl common_asctime(tm const *const tm_value) throw ()
 
char *__cdecl asctime (tm const *const tm_value)
 
wchar_t *__cdecl _wasctime (tm const *const tm_value)
 

Macro Definition Documentation

◆ _ASCBUFSIZE

#define _ASCBUFSIZE   26

Definition at line 11 of file asctime.cpp.

Function Documentation

◆ _In_range_()

_In_range_ ( >=  ,
_ASCBUFSIZE   
) const

◆ _Success_() [1/2]

template<typename Character >
_Success_ ( return = 0) const
throw (
)

Definition at line 166 of file asctime.cpp.

169{
170 static Character static_buffer[_ASCBUFSIZE];
171
172 Character** ptd_buffer_address = common_asctime_get_ptd_buffer(Character());
173 if (ptd_buffer_address != nullptr && *ptd_buffer_address == nullptr)
174 {
175 *ptd_buffer_address = _calloc_crt_t(Character, _ASCBUFSIZE).detach();
176 }
177
178 Character* const buffer = ptd_buffer_address != nullptr && *ptd_buffer_address != nullptr
179 ? *ptd_buffer_address
180 : static_buffer;
181
182 errno_t const status = common_asctime_s(buffer, _ASCBUFSIZE, tm_value);
183 if (status != 0)
184 return nullptr;
185
186 return buffer;
187}
#define _ASCBUFSIZE
Definition: asctime.cpp:11
static char ** common_asctime_get_ptd_buffer(char)
Definition: asctime.cpp:143
GLuint buffer
Definition: glext.h:5915
Definition: ps.c:97
int errno_t
Definition: corecrt.h:615

◆ _Success_() [2/2]

template<typename Character >
_Success_ ( return  = = 0) const

◆ _wasctime()

wchar_t *__cdecl _wasctime ( tm const *const  tm_value)

Definition at line 194 of file asctime.cpp.

195{
196 return common_asctime<wchar_t>(tm_value);
197}

◆ _wasctime_s()

errno_t __cdecl _wasctime_s ( wchar_t *const  buffer,
size_t const  size_in_chars,
tm const *const  tm_value 
)

Definition at line 126 of file asctime.cpp.

131{
132 return common_asctime_s(buffer, size_in_chars, tm_value);
133}

◆ asctime()

char *__cdecl asctime ( tm const *const  tm_value)

Definition at line 189 of file asctime.cpp.

190{
191 return common_asctime<char>(tm_value);
192}

◆ asctime_s()

errno_t __cdecl asctime_s ( char *const  buffer,
size_t const  size_in_chars,
tm const *const  tm_value 
)

Definition at line 117 of file asctime.cpp.

122{
123 return common_asctime_s(buffer, size_in_chars, tm_value);
124}

◆ common_asctime_get_ptd_buffer() [1/2]

static char ** common_asctime_get_ptd_buffer ( char  )
throw (
)
static

Definition at line 143 of file asctime.cpp.

144{
146 if (ptd == nullptr)
147 return nullptr;
148
149 return &ptd->_asctime_buffer;
150}
__acrt_ptd *__cdecl __acrt_getptd_noexit(void)
_In_ size_t const _In_ int _In_ bool const _In_ unsigned const _In_ __acrt_rounding_mode const _Inout_ __crt_cached_ptd_host & ptd
Definition: cvt.cpp:355

Referenced by _Success_().

◆ common_asctime_get_ptd_buffer() [2/2]

static wchar_t ** common_asctime_get_ptd_buffer ( wchar_t  )
throw (
)
static

Definition at line 152 of file asctime.cpp.

153{
155 if (ptd == nullptr)
156 return nullptr;
157
158 return &ptd->_wasctime_buffer;
159}

◆ common_asctime_s_write_value()

template<typename Character >
static Character *__cdecl common_asctime_s_write_value ( _Out_writes_(2) Character *  p,
int const  value,
bool const  zero_fill 
)
throw (
)
static

Definition at line 21 of file asctime.cpp.

26{
27 if (value >= 10 || zero_fill)
28 {
29 *p++ = static_cast<Character>('0' + value / 10);
30 }
31 else
32 {
33 *p++ = ' ';
34 }
35
36 *p++ = static_cast<Character>('0' + value % 10);
37 return p;
38}
GLfloat GLfloat p
Definition: glext.h:8902
Definition: pdh_main.c:96

Referenced by throw().

◆ throw()

tm const *const tm_value throw ( )

Definition at line 54 of file asctime.cpp.

55{
57 buffer != nullptr && size_in_chars > 0,
58 EINVAL
59 )
60
61 _RESET_STRING(buffer, size_in_chars);
62
64 _VALIDATE_RETURN_ERRCODE(tm_value != nullptr, EINVAL)
65 _VALIDATE_RETURN_ERRCODE(tm_value->tm_year >= 0, EINVAL)
66
67 // Month, hour, minute, and second are zero-based
68 _VALIDATE_RETURN_ERRCODE(tm_value->tm_mon >= 0 && tm_value->tm_mon <= 11, EINVAL)
69 _VALIDATE_RETURN_ERRCODE(tm_value->tm_hour >= 0 && tm_value->tm_hour <= 23, EINVAL)
70 _VALIDATE_RETURN_ERRCODE(tm_value->tm_min >= 0 && tm_value->tm_min <= 59, EINVAL)
71 _VALIDATE_RETURN_ERRCODE(tm_value->tm_sec >= 0 && tm_value->tm_sec <= 60, EINVAL) // including leap second
72 _VALIDATE_RETURN_ERRCODE(tm_value->tm_wday >= 0 && tm_value->tm_wday <= 6, EINVAL)
73
74 _VALIDATE_RETURN_ERRCODE(__crt_time_is_day_valid(tm_value->tm_year, tm_value->tm_mon, tm_value->tm_mday), EINVAL)
75
76 Character* buffer_it = buffer;
77
78 // Copy the day name into the buffer:
79 char const* const day_first = __dnames + tm_value->tm_wday * 3;
80 char const* const day_last = day_first + 3;
81 for (char const* day_it = day_first; day_it != day_last; ++day_it)
82 *buffer_it++ = static_cast<Character>(*day_it);
83
84 *buffer_it++ = static_cast<Character>(' ');
85
86 // Copy the month name into the buffer:
87 char const* const month_first = __mnames + tm_value->tm_mon * 3;
88 char const* const month_last = month_first + 3;
89 for (char const* month_it = month_first; month_it != month_last; ++month_it)
90 *buffer_it++ = static_cast<Character>(*month_it);
91
92 *buffer_it++ = static_cast<Character>(' ');
93
94 // Copy the day of the month (1 - 31) into the buffer:
95 buffer_it = common_asctime_s_write_value(buffer_it, tm_value->tm_mday, false);
96 *buffer_it++ = static_cast<Character>(' ');
97
98 // Copy the time into the buffer in HH:MM:SS form:
99 buffer_it = common_asctime_s_write_value(buffer_it, tm_value->tm_hour, true);
100 *buffer_it++ = static_cast<Character>(':');
101 buffer_it = common_asctime_s_write_value(buffer_it, tm_value->tm_min, true);
102 *buffer_it++ = static_cast<Character>(':');
103 buffer_it = common_asctime_s_write_value(buffer_it, tm_value->tm_sec, true);
104 *buffer_it++ = static_cast<Character>(' ');
105
106 // Copy the four-digit year into the buffer:
107 buffer_it = common_asctime_s_write_value(buffer_it, __crt_get_century(tm_value->tm_year), true);
108 buffer_it = common_asctime_s_write_value(buffer_it, __crt_get_2digit_year(tm_value->tm_year), true);
109
110 // And that's it...
111 *buffer_it++ = static_cast<Character>('\n');
112 *buffer_it++ = static_cast<Character>('\0');
113
114 return 0;
115}
#define EINVAL
Definition: acclib.h:90
static Character *__cdecl common_asctime_s_write_value(_Out_writes_(2) Character *p, int const value, bool const zero_fill)
Definition: asctime.cpp:21
#define _RESET_STRING(_String, _Size)
char const __mnames[]
Definition: timeset.cpp:157
char const __dnames[]
Definition: timeset.cpp:151
bool __cdecl __crt_time_is_day_valid(int const yr, int const mo, int const dy)
int __crt_get_century(int const year)
int __crt_get_2digit_year(int const year)
#define _VALIDATE_RETURN_ERRCODE(expr, errorcode)