-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgmtime.c.diff
246 lines (236 loc) · 6.92 KB
/
gmtime.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
*** ./gmtime.c.orig Tue Jun 16 23:00:00 1998
--- ./gmtime.c Thu Feb 01 23:36:23 2001
***************
*** 1,165 ****
! /***
! *gmtime.c - breaks down a time value into GMT date/time info
! *
! * Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
! *
! *Purpose:
! * defines gmtime() - breaks the clock value down into GMT time/date
! * information; return pointer to structure with the data.
! *
! *******************************************************************************/
! #include <cruntime.h>
#include <time.h>
! #include <ctime.h>
! #include <stddef.h>
! #include <internal.h>
! #include <mtdll.h>
! #ifdef _MT
! #include <malloc.h>
! #include <stddef.h>
! #endif /* _MT */
! #include <dbgint.h>
!
! static struct tm tb = { 0 }; /* time block */
!
! /***
! *struct tm *gmtime(timp) - convert *timp to a structure (UTC)
! *
! *Purpose:
! * Converts the calendar time value, in internal format (time_t), to
! * broken-down time (tm structure) with the corresponding UTC time.
! *
! *Entry:
! * const time_t *timp - pointer to time_t value to convert
! *
! *Exit:
! * returns pointer to filled-in tm structure.
! * returns NULL if *timp < 0L
! *
! *Exceptions:
! *
! *******************************************************************************/
!
! struct tm * __cdecl gmtime (
! const time_t *timp
! )
{
! long caltim = *timp; /* calendar time to convert */
! int islpyr = 0; /* is-current-year-a-leap-year flag */
! REG1 int tmptim;
! REG3 int *mdays; /* pointer to days or lpdays */
!
! #ifdef _MT
!
! REG2 struct tm *ptb; /* will point to gmtime buffer */
! _ptiddata ptd = _getptd();
!
! #else /* _MT */
! REG2 struct tm *ptb = &tb;
! #endif /* _MT */
!
! if ( caltim < 0L )
! return(NULL);
!
! #ifdef _MT
!
! /* Use per thread buffer area (malloc space, if necessary) */
!
! if ( (ptd->_gmtimebuf != NULL) || ((ptd->_gmtimebuf =
! _malloc_crt(sizeof(struct tm))) != NULL) )
! ptb = ptd->_gmtimebuf;
! else
! ptb = &tb; /* malloc error: use static buffer */
!
! #endif /* _MT */
!
! /*
! * Determine years since 1970. First, identify the four-year interval
! * since this makes handling leap-years easy (note that 2000 IS a
! * leap year and 2100 is out-of-range).
! */
! tmptim = (int)(caltim / _FOUR_YEAR_SEC);
! caltim -= ((long)tmptim * _FOUR_YEAR_SEC);
!
! /*
! * Determine which year of the interval
! */
! tmptim = (tmptim * 4) + 70; /* 1970, 1974, 1978,...,etc. */
!
! if ( caltim >= _YEAR_SEC ) {
!
! tmptim++; /* 1971, 1975, 1979,...,etc. */
! caltim -= _YEAR_SEC;
!
! if ( caltim >= _YEAR_SEC ) {
!
! tmptim++; /* 1972, 1976, 1980,...,etc. */
! caltim -= _YEAR_SEC;
!
! /*
! * Note, it takes 366 days-worth of seconds to get past a leap
! * year.
! */
! if ( caltim >= (_YEAR_SEC + _DAY_SEC) ) {
!
! tmptim++; /* 1973, 1977, 1981,...,etc. */
! caltim -= (_YEAR_SEC + _DAY_SEC);
! }
! else {
! /*
! * In a leap year after all, set the flag.
! */
! islpyr++;
! }
! }
! }
!
! /*
! * tmptim now holds the value for tm_year. caltim now holds the
! * number of elapsed seconds since the beginning of that year.
! */
! ptb->tm_year = tmptim;
!
! /*
! * Determine days since January 1 (0 - 365). This is the tm_yday value.
! * Leave caltim with number of elapsed seconds in that day.
! */
! ptb->tm_yday = (int)(caltim / _DAY_SEC);
! caltim -= (long)(ptb->tm_yday) * _DAY_SEC;
!
! /*
! * Determine months since January (0 - 11) and day of month (1 - 31)
! */
! if ( islpyr )
! mdays = _lpdays;
! else
! mdays = _days;
!
!
! for ( tmptim = 1 ; mdays[tmptim] < ptb->tm_yday ; tmptim++ ) ;
!
! ptb->tm_mon = --tmptim;
!
! ptb->tm_mday = ptb->tm_yday - mdays[tmptim];
!
! /*
! * Determine days since Sunday (0 - 6)
! */
! ptb->tm_wday = ((int)(*timp / _DAY_SEC) + _BASE_DOW) % 7;
!
! /*
! * Determine hours since midnight (0 - 23), minutes after the hour
! * (0 - 59), and seconds after the minute (0 - 59).
! */
! ptb->tm_hour = (int)(caltim / 3600);
! caltim -= (long)ptb->tm_hour * 3600L;
! ptb->tm_min = (int)(caltim / 60);
! ptb->tm_sec = (int)(caltim - (ptb->tm_min) * 60);
! ptb->tm_isdst = 0;
! return( (struct tm *)ptb );
}
--- 1,76 ----
! // cegmtime.c - adapted from Microsoft C Runtime
! //
! // Time-stamp: <31/01/01 21:16:08 keuchel@lightning>
! #include "celib.h"
#include <time.h>
!
! static struct tm tb = { 0 };
!
! struct tm *
! gmtime(const time_t *timp)
{
+ long caltim = *timp;
+ int islpyr = 0;
+ int tmptim;
+ int *mdays;
+
+ struct tm *ptb = &tb;
+
+ if ( caltim < 0L )
+ return(NULL);
+
+ tmptim = (int)(caltim / _FOUR_YEAR_SEC);
+ caltim -= ((long)tmptim * _FOUR_YEAR_SEC);
+
+ tmptim = (tmptim * 4) + 70;
+
+ if ( caltim >= _YEAR_SEC )
+ {
+ tmptim++;
+ caltim -= _YEAR_SEC;
+
+ if ( caltim >= _YEAR_SEC )
+ {
+ tmptim++;
+ caltim -= _YEAR_SEC;
+
+ if ( caltim >= (_YEAR_SEC + _DAY_SEC) )
+ {
+ tmptim++;
+ caltim -= (_YEAR_SEC + _DAY_SEC);
+ }
+ else
+ {
+ islpyr++;
+ }
+ }
+ }
+
+ ptb->tm_year = tmptim;
+
+ ptb->tm_yday = (int)(caltim / _DAY_SEC);
+ caltim -= (long)(ptb->tm_yday) * _DAY_SEC;
+
+ if ( islpyr )
+ mdays = _lpdays;
+ else
+ mdays = _days;
+
+ for ( tmptim = 1 ; mdays[tmptim] < ptb->tm_yday ; tmptim++ ) ;
+
+ ptb->tm_mon = --tmptim;
+
+ ptb->tm_mday = ptb->tm_yday - mdays[tmptim];
! ptb->tm_wday = ((int)(*timp / _DAY_SEC) + _BASE_DOW) % 7;
! ptb->tm_hour = (int)(caltim / 3600);
! caltim -= (long)ptb->tm_hour * 3600L;
! ptb->tm_min = (int)(caltim / 60);
! ptb->tm_sec = (int)(caltim - (ptb->tm_min) * 60);
+ ptb->tm_isdst = 0;
+ return( (struct tm *)ptb );
}