diff options
author | Jeff Johnston <jjohnstn@redhat.com> | 2005-02-25 22:31:21 +0000 |
---|---|---|
committer | Jeff Johnston <jjohnstn@redhat.com> | 2005-02-25 22:31:21 +0000 |
commit | 1139537a2536b2ca1632f5ab991935ba25068bcb (patch) | |
tree | 083b83bc1087094af4a566d7167ef1590d8943b9 /newlib/libc/time/mktime.c | |
parent | 6d11044c633bc7aca545c5409327ef023646205b (diff) | |
download | cygnal-1139537a2536b2ca1632f5ab991935ba25068bcb.tar.gz cygnal-1139537a2536b2ca1632f5ab991935ba25068bcb.tar.bz2 cygnal-1139537a2536b2ca1632f5ab991935ba25068bcb.zip |
2005-02-25 Eric Blake <ebb9@byu.net>
* libc/include/time.h (__tzrule_struct): Make offset long, since
a 16-bit int overflows on a 12-hour offset.
* libc/sys/linux/include/time.h: Ditto.
* libc/time/mktime.c (mktime): Use new type of __tzrule.offset.
* libc/time/mktm_r.c: Ditto.
* libc/time/gettzinfo.c: Ditto.
* libc/time/strftime.c (strftime): Fix '%x' to deal with negative
years. Fix '%z' to use long, not int.
Diffstat (limited to 'newlib/libc/time/mktime.c')
-rw-r--r-- | newlib/libc/time/mktime.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/newlib/libc/time/mktime.c b/newlib/libc/time/mktime.c index 8cd9564a9..0ee055cd0 100644 --- a/newlib/libc/time/mktime.c +++ b/newlib/libc/time/mktime.c @@ -211,9 +211,12 @@ mktime (tim_p) { /* calculate start of dst in dst local time and start of std in both std local time and dst local time */ - time_t startdst_dst = tz->__tzrule[0].change - tz->__tzrule[1].offset; - time_t startstd_dst = tz->__tzrule[1].change - tz->__tzrule[1].offset; - time_t startstd_std = tz->__tzrule[1].change - tz->__tzrule[0].offset; + time_t startdst_dst = tz->__tzrule[0].change + - (time_t) tz->__tzrule[1].offset; + time_t startstd_dst = tz->__tzrule[1].change + - (time_t) tz->__tzrule[1].offset; + time_t startstd_std = tz->__tzrule[1].change + - (time_t) tz->__tzrule[0].offset; /* if the time is in the overlap between dst and std local times */ if (tim >= startstd_std && tim < startstd_dst) ; /* we let user decide or leave as -1 */ @@ -226,8 +229,12 @@ mktime (tim_p) if ((isdst ^ tim_p->tm_isdst) == 1) { /* we either subtract or add the difference between - time zone offsets, depending on which way the user got it wrong */ - int diff = tz->__tzrule[0].offset - tz->__tzrule[1].offset; + time zone offsets, depending on which way the user got it + wrong. The diff is typically one hour, or 3600 seconds, + and should fit in a 16-bit int, even though offset + is a long to accomodate 12 hours. */ + int diff = (int) (tz->__tzrule[0].offset + - tz->__tzrule[1].offset); if (!isdst) diff = -diff; tim_p->tm_sec += diff; @@ -240,9 +247,9 @@ mktime (tim_p) /* add appropriate offset to put time in gmt format */ if (isdst == 1) - tim += tz->__tzrule[1].offset; + tim += (time_t) tz->__tzrule[1].offset; else /* otherwise assume std time */ - tim += tz->__tzrule[0].offset; + tim += (time_t) tz->__tzrule[0].offset; /* reset isdst flag to what we have calculated */ tim_p->tm_isdst = isdst; |