comparison src/core/ngx_times.c @ 7103:644d0457782a

Fixed ngx_gmtime() on 32-bit platforms with 64-bit time_t. In ngx_gmtime(), instead of casting to ngx_uint_t we now work with time_t directly. This allows using dates after 2038 on 32-bit platforms which use 64-bit time_t, notably NetBSD and OpenBSD. As the code is not able to work with negative time_t values, argument is now set to 0 for negative values. As a positive side effect, this results in Epoch being used for such values instead of a date in distant future.
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 13 Sep 2017 15:52:01 +0300
parents 63699a40e2ff
children cdbcb73239ee
comparison
equal deleted inserted replaced
7102:63699a40e2ff 7103:644d0457782a
298 298
299 void 299 void
300 ngx_gmtime(time_t t, ngx_tm_t *tp) 300 ngx_gmtime(time_t t, ngx_tm_t *tp)
301 { 301 {
302 ngx_int_t yday; 302 ngx_int_t yday;
303 ngx_uint_t n, sec, min, hour, mday, mon, year, wday, days, leap; 303 ngx_uint_t sec, min, hour, mday, mon, year, wday, days, leap;
304 304
305 /* the calculation is valid for positive time_t only */ 305 /* the calculation is valid for positive time_t only */
306 306
307 n = (ngx_uint_t) t; 307 if (t < 0) {
308 308 t = 0;
309 days = n / 86400; 309 }
310
311 days = t / 86400;
312 sec = t % 86400;
310 313
311 /* January 1, 1970 was Thursday */ 314 /* January 1, 1970 was Thursday */
312 315
313 wday = (4 + days) % 7; 316 wday = (4 + days) % 7;
314 317
315 n %= 86400; 318 hour = sec / 3600;
316 hour = n / 3600; 319 sec %= 3600;
317 n %= 3600; 320 min = sec / 60;
318 min = n / 60; 321 sec %= 60;
319 sec = n % 60;
320 322
321 /* 323 /*
322 * the algorithm based on Gauss' formula, 324 * the algorithm based on Gauss' formula,
323 * see src/core/ngx_parse_time.c 325 * see src/core/ngx_parse_time.c
324 */ 326 */