-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathftime.c.diff
283 lines (271 loc) · 6.96 KB
/
ftime.c.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
*** ./ftime.c.orig Tue Jun 16 23:00:00 1998
--- ./ftime.c Thu Feb 01 23:36:23 2001
***************
*** 1,194 ****
! /***
! *ftime.c - return system time
! *
! * Copyright (c) 1985-1998, Microsoft Corporation. All rights reserved.
! *
! *Purpose:
! * Returns the system date/time in a structure form.
! *
! *******************************************************************************/
! #ifdef _WIN32
!
!
!
! #include <cruntime.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <time.h>
! #include <dostypes.h>
! #include <msdos.h>
! #include <dos.h>
! #include <stdlib.h>
! #include <windows.h>
! #include <internal.h>
!
! /*
! * Number of 100 nanosecond units from 1/1/1601 to 1/1/1970
! */
#define EPOCH_BIAS 116444736000000000i64
- /*
- * Union to facilitate converting from FILETIME to unsigned __int64
- */
typedef union {
! unsigned __int64 ft_scalar;
! FILETIME ft_struct;
! } FT;
!
! /*
! * Cache for the minutes count for with DST status was last assessed
! */
static time_t elapsed_minutes_cache = 0;
- /*
- * Three values of dstflag_cache
- */
#define DAYLIGHT_TIME 1
#define STANDARD_TIME 0
#define UNKNOWN_TIME -1
- /*
- * Cache for the last determined DST status
- */
static int dstflag_cache = UNKNOWN_TIME;
! /***
! *void _ftime(timeptr) - return DOS time in a structure
! *
! *Purpose:
! * returns the current DOS time in a struct timeb structure
! *
! *Entry:
! * struct timeb *timeptr - structure to fill in with time
! *
! *Exit:
! * no return value -- fills in structure
! *
! *Exceptions:
! *
! *******************************************************************************/
!
! _CRTIMP void __cdecl _ftime (
! struct _timeb *tp
! )
{
! FT nt_time;
! time_t t;
! TIME_ZONE_INFORMATION tzinfo;
! DWORD tzstate;
!
! __tzset();
!
! tp->timezone = (short)(_timezone / 60);
!
! GetSystemTimeAsFileTime( &(nt_time.ft_struct) );
!
! /*
! * Obtain the current DST status. Note the status is cached and only
! * updated once per minute, if necessary.
! */
! if ( (t = (time_t)(nt_time.ft_scalar / 600000000i64))
! != elapsed_minutes_cache )
! {
! if ( (tzstate = GetTimeZoneInformation( &tzinfo )) != 0xFFFFFFFF )
! {
! /*
! * Must be very careful in determining whether or not DST is
! * really in effect.
! */
! if ( (tzstate == TIME_ZONE_ID_DAYLIGHT) &&
! (tzinfo.DaylightDate.wMonth != 0) &&
! (tzinfo.DaylightBias != 0) )
! dstflag_cache = DAYLIGHT_TIME;
! else
! /*
! * When in doubt, assume standard time
! */
! dstflag_cache = STANDARD_TIME;
! }
! else
! dstflag_cache = UNKNOWN_TIME;
!
! elapsed_minutes_cache = t;
! }
!
! tp->dstflag = (short)dstflag_cache;
!
! tp->millitm = (unsigned short)((nt_time.ft_scalar / 10000i64) %
! 1000i64);
! tp->time = (time_t)((nt_time.ft_scalar - EPOCH_BIAS) / 10000000i64);
}
-
-
-
- #else /* _WIN32 */
-
- #if defined (_M_MPPC) || defined (_M_M68K)
-
-
- #include <cruntime.h>
- #include <sys/types.h>
- #include <sys/timeb.h>
- #include <time.h>
- #include <stdlib.h>
- #include <internal.h>
- #include <macos\osutils.h> /* get DataTimeRec type */
- #include <macos\memory.h>
- #include <macos\lowmem.h>
-
- /***
- *void _ftime(timeptr) - return DOS time in a structure
- *
- *Purpose:
- * returns the current DOS time in a struct timeb structure
- *
- *Entry:
- * struct timeb *timeptr - structure to fill in with time
- *
- *Exit:
- * no return value -- fills in structure
- *
- *Exceptions:
- *
- *******************************************************************************/
-
- void __cdecl _ftime (
- struct _timeb *tp
- )
- {
- struct tm tb;
- DateTimeRec dt;
-
- _tzset();
- tp->timezone = (short)(_timezone / 60);
-
- GetTime(&dt);
-
- /*set milliseconds*/
-
- tp->millitm = (unsigned short)( ((LMGetTicks() % 60) * 50) / 3);
-
- tb.tm_year = dt.year - 1900;
- tb.tm_mday = dt.day;
- tb.tm_mon = dt.month - 1; //[1-12]=>[0-11]
- tb.tm_hour = dt.hour;
- tb.tm_min = dt.minute;
- tb.tm_sec = dt.second;
- tb.tm_wday = dt.dayOfWeek - 1; //[1-7]=>[0-6]
- tb.tm_isdst = -1;
-
- /*
- * Call mktime() to compute time_t value and Daylight Savings Time
- * flag.
- */
- tp->time = mktime(&tb);
-
- tp->dstflag = (short)(tb.tm_isdst);
- }
-
-
- #endif /* defined (_M_MPPC) || defined (_M_M68K) */
-
- #endif /* _WIN32 */
--- 1,84 ----
! // ftime.c - adapted from Microsoft C Runtime
! //
! // Time-stamp: <01/02/01 21:29:29 keuchel@lightning>
! #include "celib.h"
#include <sys/types.h>
#include <sys/timeb.h>
#include <time.h>
!
#define EPOCH_BIAS 116444736000000000i64
typedef union {
! unsigned __int64 ft_scalar;
! FILETIME ft_struct;
! } FT;
!
static time_t elapsed_minutes_cache = 0;
#define DAYLIGHT_TIME 1
#define STANDARD_TIME 0
#define UNKNOWN_TIME -1
static int dstflag_cache = UNKNOWN_TIME;
! void
! ftime (struct _timeb *tp)
{
! FT nt_time;
! time_t t;
! TIME_ZONE_INFORMATION tzinfo;
! DWORD tzstate;
!
! __tzset();
!
! tp->timezone = (short)(_timezone / 60);
!
! XCEGetSystemTimeAsFileTime(&(nt_time.ft_struct));
!
! if((t = (time_t)(nt_time.ft_scalar / 600000000i64))
! != elapsed_minutes_cache)
! {
! if((tzstate = GetTimeZoneInformation(&tzinfo)) != 0xFFFFFFFF)
! {
! if ( (tzstate == TIME_ZONE_ID_DAYLIGHT) &&
! (tzinfo.DaylightDate.wMonth != 0) &&
! (tzinfo.DaylightBias != 0) )
! dstflag_cache = DAYLIGHT_TIME;
! else
! dstflag_cache = STANDARD_TIME;
! }
! else
! dstflag_cache = UNKNOWN_TIME;
!
! elapsed_minutes_cache = t;
! }
!
! tp->dstflag = (short)dstflag_cache;
!
! #if 0
! {
! SYSTEMTIME st;
!
! // millis are always 0?
! GetSystemTime(&st);
! tp->millitm = st.wMilliseconds;
! }
! #endif
!
! #if 0
! {
! // this evals to on WinCE
! tp->millitm = (unsigned short)((nt_time.ft_scalar / 10000i64) %
! 1000i64);
! }
! #endif
!
! #if 1
! {
! tp->millitm = GetTickCount() % 1000;
! }
! #endif
! tp->time = (time_t)((nt_time.ft_scalar - EPOCH_BIAS) / 10000000i64);
}