diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2018-08-31 23:45:31 -0700 |
---|---|---|
committer | Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr> | 2018-10-24 12:52:49 +0200 |
commit | d6713c0eec62c6e3f8abff9c61e71e61aae70fd3 (patch) | |
tree | 06d71f30bb4f46f03d7d79311007c4db6c6515b9 /time/timegm.c | |
parent | 2a2c7fa964baec86271b4df8d9c1bb13d9495b56 (diff) | |
download | glibc-d6713c0eec62c6e3f8abff9c61e71e61aae70fd3.zip glibc-d6713c0eec62c6e3f8abff9c61e71e61aae70fd3.tar.gz glibc-d6713c0eec62c6e3f8abff9c61e71e61aae70fd3.tar.bz2 |
Y2038: make __mktime_internal compatible with __time64_t
This implies also making its callers 64-bit-time compatible
(these are mktime/localtime and timegm) and providing wrappers
for 32-bit-time userland to call.
This patch was tested by running 'make check' on branch
master then applying this patch and its two predecessors and
running 'make check' again, and checking that both 'make check'
yield identical results. This was done on x86_64-linux-gnu and
i686-linux-gnu.
* include/time.h (__mktime64): Add prototype.
* include/time.h (__localtime64): Likewise.
* include/time.h (fits_in_time_t): New static function.
* time/mktime.c (__mktime64): New function.
* time/timegm.c (__timegm64): Likewise.
* time/mktime.c (mktime) [__TIMESIZE]: New wrapper function.
* time/timegm.c (timegm) [__TIMESIZE]: Likewise.
Diffstat (limited to 'time/timegm.c')
-rw-r--r-- | time/timegm.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/time/timegm.c b/time/timegm.c index 229fff2..e7718ee 100644 --- a/time/timegm.c +++ b/time/timegm.c @@ -24,11 +24,26 @@ #include <time.h> #include "mktime-internal.h" +#include <errno.h> + +__time64_t +__timegm64 (struct tm *tmp) +{ + static long int gmtime_offset; + tmp->tm_isdst = 0; + return __mktime_internal (tmp, __gmtime64_r, &gmtime_offset); +} + +#if __TIMESIZE != 64 time_t timegm (struct tm *tmp) { - static mktime_offset_t gmtime_offset; - tmp->tm_isdst = 0; - return __mktime_internal (tmp, __gmtime_r, &gmtime_offset); + __time64_t t64 = __timegm64 (tmp); + if (fits_in_time_t (t64)) + return t64; + __set_errno (EOVERFLOW); + return -1; } + +#endif |