diff options
author | Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr> | 2018-04-11 21:32:34 +0200 |
---|---|---|
committer | Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr> | 2018-06-15 20:05:16 +0200 |
commit | 66f277a3a40f369ca8e583d410f5f7771da5aa61 (patch) | |
tree | 4b1b7e57f3fdd33bd8d75fa97a160ddecb5088db /time/gmtime.c | |
parent | 38a873073548a9a52136067df65cf47103e3342b (diff) | |
download | glibc-aaribaud/tmp.tar.gz |
Y2038: make __tz_convert compatible with 64-bit-timeaaribaud/tmp
This implies that its callers be 64-bit-time compatible too.
It is done by creating 64-bit-time versions of these and
turning their original 32-bit-time versions into wrappers
(at a slight execution time cost).
The callers affected are:
* localtime
* localtime_r
* ctime
* ctime_r
* gmtime
* gmtime_r
Note that in time/tzfile.c we do not need to check for time_t
overflows anymore as introduced by commit fc79706a323 since we
now use internal_time_t.
Diffstat (limited to 'time/gmtime.c')
-rw-r--r-- | time/gmtime.c | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/time/gmtime.c b/time/gmtime.c index dc33b3e68a..689784d22e 100644 --- a/time/gmtime.c +++ b/time/gmtime.c @@ -17,21 +17,51 @@ <http://www.gnu.org/licenses/>. */ #include <time.h> +#include <errno.h> + +/* Return the `struct tm' representation of 64-bit-time *T + in UTC, using *TP to store the result. */ +struct tm * +__gmtime64_r (const __time64_t *t, struct tm *tp) +{ + return __tz_convert (*t, 0, tp); +} + +/* Provide a 32-bit wrapper if needed */ + +#if __TIMESIZE != 64 -/* Return the `struct tm' representation of *T in UTC, - using *TP to store the result. */ struct tm * __gmtime_r (const time_t *t, struct tm *tp) { - return __tz_convert (t, 0, tp); + __time64_t t64 = *t; + return __gmtime64_r (&t64, tp); } + +#endif + +/* This always works because either __TIMESIZE != 64 and __gmtime_r exists + or __TIMESIZE == 64 and the definition of __gmtime64_r above actually + defined __gmtime_r. */ libc_hidden_def (__gmtime_r) weak_alias (__gmtime_r, gmtime_r) +/* Return the `struct tm' representation of 64-bit-time *T in UTC. */ +struct tm * +__gmtime64 (const __time64_t *t) +{ + return __tz_convert (*t, 0, &_tmbuf); +} + +/* Provide a 32-bit wrapper if needed */ + +#if __TIMESIZE != 64 -/* Return the `struct tm' representation of *T in UTC. */ struct tm * gmtime (const time_t *t) { - return __tz_convert (t, 0, &_tmbuf); + __time64_t t64 = *t; + return __gmtime64 (&t64); } + +#endif |