X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=src%2Ftime%2Fmktime.c;h=e38b46191c50b1346cb8cafddfe0b85f5ecd14ac;hp=858cd50d012bfacd0aabf735e35d956a51e4967b;hb=1cc81f5cb0df2b66a795ff0c26d7bbc4d16e13c6;hpb=f1292e3d28309bbc81f61671164843cec4319bfa diff --git a/src/time/mktime.c b/src/time/mktime.c index 858cd50d..e38b4619 100644 --- a/src/time/mktime.c +++ b/src/time/mktime.c @@ -1,24 +1,30 @@ -#include - -#include "__time.h" +#include "time_impl.h" +#include +#include +#include time_t mktime(struct tm *tm) { - int isdst = tm->tm_isdst; - time_t t, lt; + 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); - __tzset(); + if (tm->tm_isdst>=0 && new.tm_isdst!=tm->tm_isdst) + t += opp - new.__tm_gmtoff; - tm->tm_sec += __timezone; - if (isdst > 0) tm->tm_sec += __dst_offset; + t += new.__tm_gmtoff; + if ((time_t)t != t) goto error; - t = __tm_to_time(tm); - - lt = t - __timezone; - if (isdst > 0) lt -= __dst_offset; - __time_to_tm(lt, tm); + __secs_to_zone(t, 0, &new.tm_isdst, &new.__tm_gmtoff, &opp, &new.__tm_zone); - __dst_adjust(tm); - + if (__secs_to_tm(t - new.__tm_gmtoff, &new) < 0) goto error; + + *tm = new; return t; + +error: + errno = EINVAL; + return -1; }