ReactOS 0.4.16-dev-732-g2d1144a
strdate.cpp
Go to the documentation of this file.
1//
2// strdate.cpp
3//
4// Copyright (c) Microsoft Corporation. All rights reserved.
5//
6// The strdate() family of functions, which return the current data as a string.
7//
10
11
12// Returns the current date as a string of the form "MM/DD/YY". These functions
13// return an error code on failure, or zero on success. The buffer must be at
14// least nine characters in size.
15template <typename Character>
17 _Out_writes_z_(size_in_chars) Character* const buffer,
18 _In_ _In_range_(>=, 9) size_t const size_in_chars
19 ) throw()
20{
21 _VALIDATE_RETURN_ERRCODE(buffer != nullptr && size_in_chars > 0, EINVAL);
22 _RESET_STRING(buffer, size_in_chars);
23 _VALIDATE_RETURN_ERRCODE(size_in_chars >= 9, ERANGE);
24
27
28 int const month = local_time.wMonth;
29 int const day = local_time.wDay;
30 int const year = local_time.wYear % 100;
31
32 static Character const zero_char = static_cast<Character>('0');
33
34#pragma warning(disable:__WARNING_POTENTIAL_BUFFER_OVERFLOW_HIGH_PRIORITY) // 26015
35
36 // Store the components of the date into the string in MM/DD/YY form:
37 buffer[0] = static_cast<Character>(month / 10 + zero_char); // Tens of month
38 buffer[1] = static_cast<Character>(month % 10 + zero_char); // Units of month
39 buffer[2] = static_cast<Character>('/');
40 buffer[3] = static_cast<Character>(day / 10 + zero_char); // Tens of day
41 buffer[4] = static_cast<Character>(day % 10 + zero_char); // Units of day
42 buffer[5] = static_cast<Character>('/');
43 buffer[6] = static_cast<Character>(year / 10 + zero_char); // Tens of year
44 buffer[7] = static_cast<Character>(year % 10 + zero_char); // Units of year
45 buffer[8] = static_cast<Character>('\0');
46
47 return 0;
48}
49
50extern "C" errno_t __cdecl _strdate_s(char* const buffer, size_t const size_in_chars)
51{
52 return common_strdate_s(buffer, size_in_chars);
53}
54
55extern "C" errno_t __cdecl _wstrdate_s(wchar_t* const buffer, size_t const size_in_chars)
56{
57 return common_strdate_s(buffer, size_in_chars);
58}
59
60
61
62// Returns the current date as a string of the form "MM/DD/YY". These functions
63// assume that the provided result buffer is at least nine characters in length.
64// Each returns the buffer on success, or null on failure.
65template <typename Character>
66_Success_(return != 0)
67static Character* __cdecl common_strdate(_Out_writes_z_(9) Character* const buffer) throw()
68{
70 if (status != 0)
71 return nullptr;
72
73 return buffer;
74}
75
76extern "C" char* __cdecl _strdate(char* const buffer)
77{
78 return common_strdate(buffer);
79}
80
81extern "C" wchar_t* __cdecl _wstrdate(wchar_t* const buffer)
82{
83 return common_strdate(buffer);
84}
#define EINVAL
Definition: acclib.h:90
#define ERANGE
Definition: acclib.h:92
#define __cdecl
Definition: accygwin.h:79
#define _RESET_STRING(_String, _Size)
_wstrdate
result_buffer_count char *const _In_ int const _In_ bool const _In_ unsigned const _In_ STRFLT const _In_ bool const _Inout_ __crt_cached_ptd_host &ptd throw()
Definition: cvt.cpp:119
static DOUBLE local_time(DOUBLE time, DateInstance *date)
Definition: date.c:351
static DOUBLE day(DOUBLE time)
Definition: date.c:117
VOID WINAPI GetLocalTime(OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:286
static const WCHAR month[12][4]
Definition: session.c:2150
GLuint buffer
Definition: glext.h:5915
#define _VALIDATE_RETURN_ERRCODE(expr, errorcode)
#define _Out_writes_z_(s)
Definition: no_sal2.h:180
#define _Success_(c)
Definition: no_sal2.h:84
#define _In_
Definition: no_sal2.h:158
#define _In_range_(l, h)
Definition: no_sal2.h:368
_strdate
Definition: time.h:297
errno_t __cdecl _wstrdate_s(wchar_t *const buffer, size_t const size_in_chars)
Definition: strdate.cpp:55
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)
Definition: strdate.cpp:16
errno_t __cdecl _strdate_s(char *const buffer, size_t const size_in_chars)
Definition: strdate.cpp:50
Definition: ps.c:97
int errno_t
Definition: corecrt.h:615
#define const
Definition: zconf.h:233