this commit has two major user-visible parts: zoneinfo-format time zones are now supported, and overflow handling is intended to be complete in the sense that all functions return a correct result if and only if the result fits in the destination type, and otherwise return an error. also, some noticable bugs in the way DST detection and normalization worked have been fixed, and performance may be better than before, but it has not been tested.
31 lines
598 B
C
31 lines
598 B
C
#include "time_impl.h"
|
|
#include <errno.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
time_t mktime(struct tm *tm)
|
|
{
|
|
struct tm new;
|
|
long opp;
|
|
long long t = __tm_to_secs(tm);
|
|
|
|
__secs_to_zone(t, 1, &new.tm_isdst, &new.__tm_gmtoff, &opp, &new.__tm_zone);
|
|
|
|
if (tm->tm_isdst>=0 && new.tm_isdst!=tm->tm_isdst)
|
|
t += opp - new.__tm_gmtoff;
|
|
|
|
t += new.__tm_gmtoff;
|
|
if ((time_t)t != t) goto error;
|
|
|
|
__secs_to_zone(t, 0, &new.tm_isdst, &new.__tm_gmtoff, &opp, &new.__tm_zone);
|
|
|
|
if (__secs_to_tm(t - new.__tm_gmtoff, &new) < 0) goto error;
|
|
|
|
*tm = new;
|
|
return t;
|
|
|
|
error:
|
|
errno = EINVAL;
|
|
return -1;
|
|
}
|