]> sourceware.org Git - glibc.git/commitdiff
Y2038: make __tz_convert compatible with 64-bit-time
authorAlbert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
Wed, 5 Dec 2018 20:01:22 +0000 (21:01 +0100)
committerAlbert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
Wed, 5 Dec 2018 20:01:22 +0000 (21:01 +0100)
Now that __time64_t exists, we can switch internal function
__tz_convert from 32-bit to 64-bit time. This involves switching
some other internal functions as well, namely __tz_compute and
__offtime.

Tested with 'make check' on x86_64-linux-gnu and i686-linux.gnu.

* include/time.h
(__tz_compute): Replace time_t with __time64_t.
(__tz_convert): Replace time_t* with __time64_t.
(__offtime): Replace time_t* with __time64_t.
* time/gmtime.c
(__gmtime_r): Adjust call to __tz_convert.
(gmtime): Likewise.
* time/localtime.c
(__localtime_r): Likewise.
(localtime): Likewise.
* time/offtime.c: Replace time_t with __time64_t.
* time/tzset.c: Likewise.

ChangeLog
include/time.h
time/gmtime.c
time/localtime.c
time/offtime.c
time/tzfile.c
time/tzset.c

index 4138a08b4e1d94a7de08ffa210e388b97637a6bf..935863b7b2d7cab5de4363af403656a9ba0b89ab 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2018-12-05  Albert ARIBAUD <albert.aribaud@3adev.fr>
+
+       * include/time.h
+       (__tz_compute): Replace time_t with __time64_t.
+       (__tz_convert): Replace time_t* with __time64_t.
+       (__offtime): Replace time_t* with __time64_t.
+       * time/gmtime.c
+       (__gmtime_r): Adjust call to __tz_convert.
+       (gmtime): Likewise.
+       * time/localtime.c
+       (__localtime_r): Likewise.
+       (localtime): Likewise.
+       * time/offtime.c: Replace time_t with __time64_t.
+       * time/tzset.c: Likewise.
+
 2018-12-04  Joseph Myers  <joseph@codesourcery.com>
 
        * Makefile ($(objpfx)testroot.pristine/install.stamp): Do not run
index 861b1acfb7f514aa224d62cb6eca3f587f60be18..37964f7b7617a0536b38b4b14981810f2d46dee9 100644 (file)
@@ -46,7 +46,7 @@ extern void __tzfile_default (const char *std, const char *dst,
                              long int stdoff, long int dstoff)
   attribute_hidden;
 extern void __tzset_parse_tz (const char *tz) attribute_hidden;
-extern void __tz_compute (time_t timer, struct tm *tm, int use_localtime)
+extern void __tz_compute (__time64_t timer, struct tm *tm, int use_localtime)
   __THROW attribute_hidden;
 
 /* Subroutine of `mktime'.  Return the `time_t' representation of TP and
@@ -63,11 +63,11 @@ extern struct tm *__gmtime_r (const time_t *__restrict __timer,
                              struct tm *__restrict __tp);
 libc_hidden_proto (__gmtime_r)
 
-/* Compute the `struct tm' representation of *T,
+/* Compute the `struct tm' representation of T,
    offset OFFSET seconds east of UTC,
    and store year, yday, mon, mday, wday, hour, min, sec into *TP.
    Return nonzero if successful.  */
-extern int __offtime (const time_t *__timer,
+extern int __offtime (__time64_t __timer,
                      long int __offset,
                      struct tm *__tp) attribute_hidden;
 
@@ -76,7 +76,7 @@ extern char *__asctime_r (const struct tm *__tp, char *__buf)
 extern void __tzset (void) attribute_hidden;
 
 /* Prototype for the internal function to get information based on TZ.  */
-extern struct tm *__tz_convert (const time_t *timer, int use_localtime,
+extern struct tm *__tz_convert (__time64_t timer, int use_localtime,
                                struct tm *tp) attribute_hidden;
 
 extern int __nanosleep (const struct timespec *__requested_time,
index dc33b3e68ab67a0748528fd07757a4cafdd5a3eb..bda09bc021b301997f82b33d33e786b991cf5137 100644 (file)
@@ -23,7 +23,7 @@
 struct tm *
 __gmtime_r (const time_t *t, struct tm *tp)
 {
-  return __tz_convert (t, 0, tp);
+  return __tz_convert (*t, 0, tp);
 }
 libc_hidden_def (__gmtime_r)
 weak_alias (__gmtime_r, gmtime_r)
@@ -33,5 +33,5 @@ weak_alias (__gmtime_r, gmtime_r)
 struct tm *
 gmtime (const time_t *t)
 {
-  return __tz_convert (t, 0, &_tmbuf);
+  return __tz_convert (*t, 0, &_tmbuf);
 }
index 8684a8a9713fd4638270fd0b2390781f9b7bb102..92dbfe0f8c89e053fe5388c98ea8e7dea3b118b2 100644 (file)
@@ -27,7 +27,7 @@ struct tm _tmbuf;
 struct tm *
 __localtime_r (const time_t *t, struct tm *tp)
 {
-  return __tz_convert (t, 1, tp);
+  return __tz_convert (*t, 1, tp);
 }
 weak_alias (__localtime_r, localtime_r)
 
@@ -36,6 +36,6 @@ weak_alias (__localtime_r, localtime_r)
 struct tm *
 localtime (const time_t *t)
 {
-  return __tz_convert (t, 1, &_tmbuf);
+  return __tz_convert (*t, 1, &_tmbuf);
 }
 libc_hidden_def (localtime)
index 04c48389fc288bf543eda4bf9e1e0fd7356950c3..3309fcd484daa6de7d06831333dd9dd1c8072117 100644 (file)
 #define        SECS_PER_HOUR   (60 * 60)
 #define        SECS_PER_DAY    (SECS_PER_HOUR * 24)
 
-/* Compute the `struct tm' representation of *T,
+/* Compute the `struct tm' representation of T,
    offset OFFSET seconds east of UTC,
    and store year, yday, mon, mday, wday, hour, min, sec into *TP.
    Return nonzero if successful.  */
 int
-__offtime (const time_t *t, long int offset, struct tm *tp)
+__offtime (__time64_t t, long int offset, struct tm *tp)
 {
-  time_t days, rem, y;
+  __time64_t days, rem, y;
   const unsigned short int *ip;
 
-  days = *t / SECS_PER_DAY;
-  rem = *t % SECS_PER_DAY;
+  days = t / SECS_PER_DAY;
+  rem = t % SECS_PER_DAY;
   rem += offset;
   while (rem < 0)
     {
@@ -60,7 +60,7 @@ __offtime (const time_t *t, long int offset, struct tm *tp)
   while (days < 0 || days >= (__isleap (y) ? 366 : 365))
     {
       /* Guess a corrected year, assuming 365 days per year.  */
-      time_t yg = y + days / 365 - (days % 365 < 0);
+      __time64_t yg = y + days / 365 - (days % 365 < 0);
 
       /* Adjust DAYS and Y to match the guessed year.  */
       days -= ((yg - y) * 365
index 844a68de8cea6a579e70e5c5b488c614877b417e..3920525bf3f805b64cd5f87ec2f9e0dfe21bdfa6 100644 (file)
@@ -633,16 +633,10 @@ __tzfile_compute (__time64_t timer, int use_localtime,
 
          /* Convert to broken down structure.  If this fails do not
             use the string.  */
-         {
-           time_t truncated = timer;
-           if (__glibc_unlikely (truncated != timer
-                                 || ! __offtime (&truncated, 0, tp)))
-             goto use_last;
-         }
-
-         /* Use the rules from the TZ string to compute the change.
-            timer fits into time_t due to the truncation check
-            above.  */
+         if (__glibc_unlikely (! __offtime (timer, 0, tp)))
+           goto use_last;
+
+         /* Use the rules from the TZ string to compute the change.  */
          __tz_compute (timer, tp, 1);
 
          /* If tzspec comes from posixrules loaded by __tzfile_default,
index a828b9fb75bed6ca18460d32c83e31eb30e161b7..834cc3ccec63b67f9e0ec422f203e6ef2817b70b 100644 (file)
@@ -16,7 +16,6 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <ctype.h>
-#include <errno.h>
 #include <libc-lock.h>
 #include <stdbool.h>
 #include <stddef.h>
@@ -27,7 +26,7 @@
 
 #include <timezone/tzfile.h>
 
-#define SECSPERDAY ((time_t) 86400)
+#define SECSPERDAY ((__time64_t) 86400)
 
 char *__tzname[2] = { (char *) "GMT", (char *) "GMT" };
 int __daylight = 0;
@@ -55,7 +54,7 @@ typedef struct
 
     /* We cache the computed time of change for a
        given year so we don't have to recompute it.  */
-    time_t change;     /* When to change to this zone.  */
+    __time64_t change; /* When to change to this zone.  */
     int computed_for;  /* Year above is computed for.  */
   } tz_rule;
 
@@ -416,7 +415,7 @@ tzset_internal (int always)
       tz_rules[0].name = tz_rules[1].name = "UTC";
       if (J0 != 0)
        tz_rules[0].type = tz_rules[1].type = J0;
-      tz_rules[0].change = tz_rules[1].change = (time_t) -1;
+      tz_rules[0].change = tz_rules[1].change = -1;
       update_vars ();
       return;
     }
@@ -424,13 +423,13 @@ tzset_internal (int always)
   __tzset_parse_tz (tz);
 }
 \f
-/* Figure out the exact time (as a time_t) in YEAR
+/* Figure out the exact time (as a __time64_t) in YEAR
    when the change described by RULE will occur and
    put it in RULE->change, saving YEAR in RULE->computed_for.  */
 static void
 compute_change (tz_rule *rule, int year)
 {
-  time_t t;
+  __time64_t t;
 
   if (year != -1 && rule->computed_for == year)
     /* Operations on times in 2 BC will be slower.  Oh well.  */
@@ -516,7 +515,7 @@ compute_change (tz_rule *rule, int year)
 /* Figure out the correct timezone for TM and set `__tzname',
    `__timezone', and `__daylight' accordingly.  */
 void
-__tz_compute (time_t timer, struct tm *tm, int use_localtime)
+__tz_compute (__time64_t timer, struct tm *tm, int use_localtime)
 {
   compute_change (&tz_rules[0], 1900 + tm->tm_year);
   compute_change (&tz_rules[1], 1900 + tm->tm_year);
@@ -562,20 +561,14 @@ __tzset (void)
 }
 weak_alias (__tzset, tzset)
 \f
-/* Return the `struct tm' representation of *TIMER in the local timezone.
+/* Return the `struct tm' representation of TIMER in the local timezone.
    Use local time if USE_LOCALTIME is nonzero, UTC otherwise.  */
 struct tm *
-__tz_convert (const time_t *timer, int use_localtime, struct tm *tp)
+__tz_convert (__time64_t timer, int use_localtime, struct tm *tp)
 {
   long int leap_correction;
   int leap_extra_secs;
 
-  if (timer == NULL)
-    {
-      __set_errno (EINVAL);
-      return NULL;
-    }
-
   __libc_lock_lock (tzset_lock);
 
   /* Update internal database according to current TZ setting.
@@ -584,14 +577,14 @@ __tz_convert (const time_t *timer, int use_localtime, struct tm *tp)
   tzset_internal (tp == &_tmbuf && use_localtime);
 
   if (__use_tzfile)
-    __tzfile_compute (*timer, use_localtime, &leap_correction,
+    __tzfile_compute (timer, use_localtime, &leap_correction,
                      &leap_extra_secs, tp);
   else
     {
       if (! __offtime (timer, 0, tp))
        tp = NULL;
       else
-       __tz_compute (*timer, tp, use_localtime);
+       __tz_compute (timer, tp, use_localtime);
       leap_correction = 0L;
       leap_extra_secs = 0;
     }
This page took 0.080806 seconds and 5 git commands to generate.