ReactOS 0.4.16-dev-853-g88d9285
ftime.cpp
Go to the documentation of this file.
1//
2// ftime.cpp
3//
4// Copyright (c) Microsoft Corporation. All rights reserved.
5//
6// The ftime() family of functions, which return the system date and time in a
7// time structure.
8//
10#include <sys/timeb.h>
11#include <sys/types.h>
12
13
14
15// Cache for the minutes count for with DST status was last assessed
16// CRT_REFACTOR TODO Check synchronization of access to this global variable.
18
19
20
21// Three values of dstflag_cache
22#define DAYLIGHT_TIME 1
23#define STANDARD_TIME 0
24#define UNKNOWN_TIME -1
25
26
27
28// Cache for the last determined DST status:
30
31
32
33// Returns the system time in a structure; returns zero on success; returns an
34// error code on failure.
35template <typename TimeType, typename TimeBType>
36static errno_t __cdecl common_ftime_s(TimeBType* const tp) throw()
37{
39
40 __tzset();
41
42 long timezone = 0;
44 tp->timezone = static_cast<short>(timezone / 60);
45
46 __crt_filetime_union system_time;
48
49 // Obtain the current Daylight Savings Time status. Note that the status is
50 // cached and only updated once per minute, if necessary.
51 TimeType const current_minutes_value = static_cast<TimeType>(system_time._scalar / 600000000ll);
52 if (static_cast<__time64_t>(current_minutes_value) != elapsed_minutes_cache)
53 {
55 DWORD const tz_state = GetTimeZoneInformation(&tz_info);
56 if (tz_state == 0xFFFFFFFF)
57 {
59 }
60 else
61 {
62 // Must be very careful when determining whether or not Daylight
63 // Savings Time is in effect:
64 if (tz_state == TIME_ZONE_ID_DAYLIGHT &&
67 {
69 }
70 else
71 {
72 // Assume Standard Time:
74 }
75 }
76
77 elapsed_minutes_cache = current_minutes_value;
78 }
79
80 tp->dstflag = static_cast<short>(dstflag_cache);
81 tp->millitm = static_cast<unsigned short>((system_time._scalar / 10000ll) % 1000ll);
82 tp->time = static_cast<TimeType>((system_time._scalar - _EPOCH_BIAS) / 10000000ll);
83
84 return 0;
85}
86
88{
89 return common_ftime_s<__time32_t>(tp);
90}
91
92extern "C" void __cdecl _ftime32(__timeb32* const tp)
93{
95}
96
98{
99 return common_ftime_s<__time64_t>(tp);
100}
101
102extern "C" void __cdecl _ftime64(__timeb64* const tp)
103{
104 _ftime64_s(tp);
105}
#define EINVAL
Definition: acclib.h:90
#define __cdecl
Definition: accygwin.h:79
VOID WINAPI __acrt_GetSystemTimePreciseAsFileTime(_Out_ LPFILETIME system_time)
#define _ERRCHECK(e)
#define _EPOCH_BIAS
void __cdecl __tzset()
Definition: tzset.cpp:392
DWORD WINAPI GetTimeZoneInformation(LPTIME_ZONE_INFORMATION lpTimeZoneInformation)
Definition: timezone.c:262
_In_ uint64_t _In_ uint64_t _In_ uint64_t _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2996
unsigned long DWORD
Definition: ntddk_ex.h:95
void __cdecl _ftime32(__timeb32 *const tp)
Definition: ftime.cpp:92
static errno_t __cdecl common_ftime_s(TimeBType *const tp)
Definition: ftime.cpp:36
static __time64_t elapsed_minutes_cache
Definition: ftime.cpp:17
errno_t __cdecl _ftime32_s(__timeb32 *const tp)
Definition: ftime.cpp:87
errno_t __cdecl _ftime64_s(__timeb64 *const tp)
Definition: ftime.cpp:97
#define UNKNOWN_TIME
Definition: ftime.cpp:24
#define STANDARD_TIME
Definition: ftime.cpp:23
static int dstflag_cache
Definition: ftime.cpp:29
#define DAYLIGHT_TIME
Definition: ftime.cpp:22
void __cdecl _ftime64(__timeb64 *const tp)
Definition: ftime.cpp:102
#define _VALIDATE_RETURN_ERRCODE(expr, errorcode)
#define TIME_ZONE_ID_DAYLIGHT
Definition: rtltypes.h:254
_CRTIMP errno_t __cdecl _get_timezone(_Out_ long *_Timezone)
WORD wMonth
Definition: winbase.h:931
SYSTEMTIME DaylightDate
Definition: winbase.h:1236
Definition: fake.h:14
static TIME_ZONE_INFORMATION tz_info
Definition: tzset.cpp:28
__int64 __time64_t
Definition: corecrt.h:619
int errno_t
Definition: corecrt.h:615