|
|
|
|
|
|
|
|
|
|
|
|
|
|
| #include <corecrt_internal_securecrt.h>
|
| #include <corecrt_internal_time.h>
|
|
|
|
|
|
|
|
|
|
|
| template <typename Character>
|
| static errno_t __cdecl common_strdate_s(
|
| _Out_writes_z_(size_in_chars) Character* const buffer,
|
| _In_ _In_range_(>=, 9) size_t const size_in_chars
|
| ) throw()
|
| {
|
| _VALIDATE_RETURN_ERRCODE(buffer != nullptr && size_in_chars > 0, EINVAL);
|
| _RESET_STRING(buffer, size_in_chars);
|
| _VALIDATE_RETURN_ERRCODE(size_in_chars >= 9, ERANGE);
|
|
|
| SYSTEMTIME local_time;
|
| GetLocalTime(&local_time);
|
|
|
| int const month = local_time.wMonth;
|
| int const day = local_time.wDay;
|
| int const year = local_time.wYear % 100;
|
|
|
| static Character const zero_char = static_cast<Character>('0');
|
|
|
| #pragma warning(disable:__WARNING_POTENTIAL_BUFFER_OVERFLOW_HIGH_PRIORITY)
|
|
|
|
|
| buffer[0] = static_cast<Character>(month / 10 + zero_char);
|
| buffer[1] = static_cast<Character>(month % 10 + zero_char);
|
| buffer[2] = static_cast<Character>('/');
|
| buffer[3] = static_cast<Character>(day / 10 + zero_char);
|
| buffer[4] = static_cast<Character>(day % 10 + zero_char);
|
| buffer[5] = static_cast<Character>('/');
|
| buffer[6] = static_cast<Character>(year / 10 + zero_char);
|
| buffer[7] = static_cast<Character>(year % 10 + zero_char);
|
| buffer[8] = static_cast<Character>('\0');
|
|
|
| return 0;
|
| }
|
|
|
| extern "C" errno_t __cdecl _strdate_s(char* const buffer, size_t const size_in_chars)
|
| {
|
| return common_strdate_s(buffer, size_in_chars);
|
| }
|
|
|
| extern "C" errno_t __cdecl _wstrdate_s(wchar_t* const buffer, size_t const size_in_chars)
|
| {
|
| return common_strdate_s(buffer, size_in_chars);
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
| template <typename Character>
|
| _Success_(return != 0)
|
| static Character* __cdecl common_strdate(_Out_writes_z_(9) Character* const buffer) throw()
|
| {
|
| errno_t const status = common_strdate_s(buffer, 9);
|
| if (status != 0)
|
| return nullptr;
|
|
|
| return buffer;
|
| }
|
|
|
| extern "C" char* __cdecl _strdate(char* const buffer)
|
| {
|
| return common_strdate(buffer);
|
| }
|
|
|
| extern "C" wchar_t* __cdecl _wstrdate(wchar_t* const buffer)
|
| {
|
| return common_strdate(buffer);
|
| }
|
|
|