This is the mail archive of the
glibc-cvs@sourceware.org
mailing list for the glibc project.
GNU C Library master sources branch aaribaud/y2038 created. glibc-2.25-7-g6c0d46a
- From: aaribaud at sourceware dot org
- To: glibc-cvs at sourceware dot org
- Date: 21 Feb 2017 22:46:39 -0000
- Subject: GNU C Library master sources branch aaribaud/y2038 created. glibc-2.25-7-g6c0d46a
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".
The branch, aaribaud/y2038 has been created
at 6c0d46abc53d19bdcbfecbb36c961d98d9447796 (commit)
- Log -----------------------------------------------------------------
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=6c0d46abc53d19bdcbfecbb36c961d98d9447796
commit 6c0d46abc53d19bdcbfecbb36c961d98d9447796
Author: Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
Date: Wed Feb 15 19:25:27 2017 +0100
Make 'time_t' either 32 or 64 bits depending on __USE_TIME_BITS64
This provides a unified set of user-facing symbol names, so
that the same user source code can build with or without _TIME_BITS=64.
diff --git a/include/time.h b/include/time.h
index 524d3ec..ef0ddb4 100644
--- a/include/time.h
+++ b/include/time.h
@@ -51,42 +51,42 @@ extern int __use_tzfile attribute_hidden;
extern void __tzfile_read (const char *file, size_t extra,
char **extrap);
-extern void __tzfile_compute (time64_t timer, int use_localtime,
+extern void __tzfile_compute (__time64_t timer, int use_localtime,
long int *leap_correct, int *leap_hit,
struct tm *tp);
extern void __tzfile_default (const char *std, const char *dst,
long int stdoff, long int dstoff);
extern void __tzset_parse_tz (const char *tz);
-extern void __tz_compute (time64_t timer, struct tm *tm, int use_localtime)
+extern void __tz_compute (__time64_t timer, struct tm *tm, int use_localtime)
__THROW internal_function;
-/* Subroutine of `mktime'. Return the `time_t' representation of TP and
- normalize TP, given that a `struct tm *' maps to a `time_t' as performed
- by FUNC. Keep track of next guess for time_t offset in *OFFSET. */
-extern time_t __mktime_internal (struct tm *__tp,
- struct tm *(*__func) (const time_t *,
+/* Subroutine of `mktime'. Return the `__time_t' representation of TP and
+ normalize TP, given that a `struct tm *' maps to a `__time_t' as performed
+ by FUNC. Keep track of next guess for __time_t offset in *OFFSET. */
+extern __time_t __mktime_internal (struct tm *__tp,
+ struct tm *(*__func) (const __time_t *,
struct tm *),
- time_t *__offset);
+ __time_t *__offset);
-/* Subroutine of `mktime64'. Return the `time64_t' representation of TP and
- normalize TP, given that a `struct tm *' maps to a `time64_t' as performed
- by FUNC. Keep track of next guess for time64_t offset in *OFFSET. */
-extern time64_t __mktime64_internal (struct tm *__tp,
- struct tm *(*__func) (const time64_t *,
+/* Subroutine of `mktime64'. Return the `__time64_t' representation of TP and
+ normalize TP, given that a `struct tm *' maps to a `__time64_t' as performed
+ by FUNC. Keep track of next guess for __time64_t offset in *OFFSET. */
+extern __time64_t __mktime64_internal (struct tm *__tp,
+ struct tm *(*__func) (const __time64_t *,
struct tm *),
- time64_t *__offset);
+ __time64_t *__offset);
-extern struct tm *__localtime_r (const time_t *__timer,
+extern struct tm *__localtime_r (const __time_t *__timer,
struct tm *__tp) attribute_hidden;
-extern struct tm *__gmtime_r (const time_t *__restrict __timer,
+extern struct tm *__gmtime_r (const __time_t *__restrict __timer,
struct tm *__restrict __tp);
libc_hidden_proto (__gmtime_r)
-extern struct tm *__localtime64_r (const time64_t *__timer,
+extern struct tm *__localtime64_r (const __time64_t *__timer,
struct tm *__tp) attribute_hidden;
-extern struct tm *__gmtime64_r (const time64_t *__restrict __timer,
+extern struct tm *__gmtime64_r (const __time64_t *__restrict __timer,
struct tm *__restrict __tp);
libc_hidden_proto (__gmtime64_r)
@@ -94,7 +94,7 @@ libc_hidden_proto (__gmtime64_r)
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 (const __time_t *__timer,
long int __offset,
struct tm *__tp);
@@ -102,7 +102,7 @@ extern int __offtime (const time_t *__timer,
offset OFFSET seconds east of UTC,
and store year, yday, mon, mday, wday, hour, min, sec into *TP.
Return nonzero if successful. */
-extern int __offtime64 (const time64_t *__timer,
+extern int __offtime64 (const __time64_t *__timer,
long int __offset,
struct tm *__tp);
@@ -110,14 +110,10 @@ extern char *__asctime_r (const struct tm *__tp, char *__buf);
extern void __tzset (void);
/* Prototype for the internal function to get information based on TZ. */
-extern struct tm *__tz_convert (const time_t *timer, int use_localtime, struct tm *tp);
+extern struct tm *__tz_convert (const __time_t *timer, int use_localtime, struct tm *tp);
/* Prototype for the internal 64-bit-time function to get information based on TZ. */
-extern struct tm *__tz64_convert (const time64_t *timer, int use_localtime, struct tm *tp);
-
-/* Prototype for the internal function to get information based on TZ,
- 64-bit-time version. */
-extern struct tm *__tz64_convert (const time64_t *timer, int use_localtime, struct tm *tp);
+extern struct tm *__tz64_convert (const __time64_t *timer, int use_localtime, struct tm *tp);
/* Return the maximum length of a timezone name.
This is what `sysconf (_SC_TZNAME_MAX)' does. */
@@ -142,8 +138,9 @@ extern char * __strptime_internal (const char *rp, const char *fmt,
__locale_t locparam)
internal_function;
-extern double __difftime (time_t time1, time_t time0);
+extern double __difftime (__time_t time1, __time_t time0);
+extern double __difftime64 (__time64_t time1, __time64_t time0);
/* Use in the clock_* functions. Size of the field representing the
actual clock ID. */
diff --git a/time/bits/types/struct_timespec.h b/time/bits/types/struct_timespec.h
index dcb0ab5..7034f3e 100644
--- a/time/bits/types/struct_timespec.h
+++ b/time/bits/types/struct_timespec.h
@@ -5,7 +5,7 @@
/* POSIX.1b structure for a time value. This is like a `struct timeval' but
has nanoseconds instead of microseconds. */
-struct timespec
+struct timespec32
{
__time_t tv_sec; /* Seconds. */
__syscall_slong_t tv_nsec; /* Nanoseconds. */
@@ -18,4 +18,10 @@ struct timespec64
__syscall_squad_t tv_nsec; /* Nanoseconds. */
};
+#ifdef __USE_TIME_BITS64
+#define timespec timespec64
+#else
+#define timespec timespec32
+#endif
+
#endif
diff --git a/time/bits/types/time_t.h b/time/bits/types/time_t.h
index 906dcf9..2a83043 100644
--- a/time/bits/types/time_t.h
+++ b/time/bits/types/time_t.h
@@ -5,17 +5,14 @@
__BEGIN_NAMESPACE_STD
/* Returned by `time'. */
+#ifdef __USE_TIME_BITS64
+typedef __time64_t time_t;
+#else
typedef __time_t time_t;
__END_NAMESPACE_STD
-#ifdef __USE_POSIX
+# ifdef __USE_POSIX
__USING_NAMESPACE_STD(time_t)
-#endif
-
-/* Returned by `time64'. */
-typedef __time64_t time64_t;
-__END_NAMESPACE_STD
-#ifdef __USE_POSIX
-__USING_NAMESPACE_STD(time64_t)
+# endif
#endif
#endif
diff --git a/time/ctime.c b/time/ctime.c
index bedb08c..eaa527d 100644
--- a/time/ctime.c
+++ b/time/ctime.c
@@ -20,7 +20,7 @@
/* Return a string as returned by asctime which
is the representation of *T in that form. */
char *
-ctime (const time_t *t)
+ctime (const __time_t *t)
{
/* The C Standard says ctime (t) is equivalent to asctime (localtime (t)).
In particular, ctime and asctime must yield the same pointer. */
@@ -30,7 +30,7 @@ ctime (const time_t *t)
/* Return a string as returned by asctime which
is the representation of *T in that form. */
char *
-ctime64 (const time64_t *t)
+ctime64 (const __time64_t *t)
{
/* Apply the same rule as ctime:
make ctime64 (t) is equivalent to asctime (localtime64 (t)). */
diff --git a/time/difftime.c b/time/difftime.c
index 47ed6e1..3288f0d 100644
--- a/time/difftime.c
+++ b/time/difftime.c
@@ -31,9 +31,9 @@
time_t is known to be an integer type. */
static double
-subtract (time_t time1, time_t time0)
+subtract (__time_t time1, __time_t time0)
{
- if (! TYPE_SIGNED (time_t))
+ if (! TYPE_SIGNED (__time_t))
return time1 - time0;
else
{
@@ -76,9 +76,9 @@ subtract (time_t time1, time_t time0)
1 is unsigned in C, so it need not be compared to zero. */
uintmax_t hdt = dt / 2;
- time_t ht1 = time1 / 2;
- time_t ht0 = time0 / 2;
- time_t dht = ht1 - ht0;
+ __time_t ht1 = time1 / 2;
+ __time_t ht0 = time0 / 2;
+ __time_t dht = ht1 - ht0;
if (2 < dht - hdt + 1)
{
@@ -99,18 +99,18 @@ subtract (time_t time1, time_t time0)
/* Return the difference between TIME1 and TIME0. */
double
-__difftime (time_t time1, time_t time0)
+__difftime (__time_t time1, __time_t time0)
{
/* Convert to double and then subtract if no double-rounding error could
result. */
- if (TYPE_BITS (time_t) <= DBL_MANT_DIG
- || (TYPE_FLOATING (time_t) && sizeof (time_t) < sizeof (long double)))
+ if (TYPE_BITS (__time_t) <= DBL_MANT_DIG
+ || (TYPE_FLOATING (__time_t) && sizeof (__time_t) < sizeof (long double)))
return (double) time1 - (double) time0;
/* Likewise for long double. */
- if (TYPE_BITS (time_t) <= LDBL_MANT_DIG || TYPE_FLOATING (time_t))
+ if (TYPE_BITS (__time_t) <= LDBL_MANT_DIG || TYPE_FLOATING (__time_t))
return (long double) time1 - (long double) time0;
/* Subtract the smaller integer from the larger, convert the difference to
@@ -122,7 +122,7 @@ strong_alias (__difftime, difftime)
/* Return the difference between 64-bit TIME1 and TIME0. */
double
-__difftime64 (time64_t time1, time64_t time0)
+__difftime64 (__time64_t time1, __time64_t time0)
{
/* Subtract the smaller integer from the larger, convert the difference to
double, and then negate if needed. */
diff --git a/time/gmtime.c b/time/gmtime.c
index 3eefeb5..06da3cd 100644
--- a/time/gmtime.c
+++ b/time/gmtime.c
@@ -39,7 +39,7 @@ gmtime (const time_t *t)
/* 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)
+__gmtime64_r (const __time64_t *t, struct tm *tp)
{
return __tz64_convert (t, 0, tp);
}
@@ -49,7 +49,7 @@ weak_alias (__gmtime64_r, gmtime64_r)
/* Return the `struct tm' representation of 64-bit-time *T in UTC. */
struct tm *
-gmtime64 (const time64_t *t)
+gmtime64 (const __time64_t *t)
{
return __tz64_convert (t, 0, &_tmbuf);
}
diff --git a/time/localtime.c b/time/localtime.c
index 8310aef..4e66966 100644
--- a/time/localtime.c
+++ b/time/localtime.c
@@ -25,7 +25,7 @@ struct tm _tmbuf;
/* Return the `struct tm' representation of *T in local time,
using *TP to store the result. */
struct tm *
-__localtime_r (const time_t *t, struct tm *tp)
+__localtime_r (const __time_t *t, struct tm *tp)
{
return __tz_convert (t, 1, tp);
}
@@ -34,7 +34,7 @@ weak_alias (__localtime_r, localtime_r)
/* Return the `struct tm' representation of *T in local time. */
struct tm *
-localtime (const time_t *t)
+localtime (const __time_t *t)
{
return __tz_convert (t, 1, &_tmbuf);
}
@@ -45,7 +45,7 @@ libc_hidden_def (localtime)
/* Return the `struct tm' representation of *T in local time,
using *TP to store the result. */
struct tm *
-__localtime64_r (const time64_t *t, struct tm *tp)
+__localtime64_r (const __time64_t *t, struct tm *tp)
{
return __tz64_convert (t, 1, tp);
}
@@ -54,7 +54,7 @@ weak_alias (__localtime64_r, localtime64_r)
/* Return the `struct tm' representation of *T in local time. */
struct tm *
-localtime64 (const time64_t *t)
+localtime64 (const __time64_t *t)
{
return __tz64_convert (t, 1, &_tmbuf);
}
diff --git a/time/mktime.c b/time/mktime.c
index b47b969..7f03d74 100644
--- a/time/mktime.c
+++ b/time/mktime.c
@@ -611,7 +611,7 @@ libc_hidden_weak (timelocal)
The result may overflow. It is the caller's responsibility to
detect overflow. */
-static time64_t
+static __time64_t
ydhms64_diff (long_int year1, long_int yday1, int hour1, int min1, int sec1,
int year0, int yday0, int hour0, int min0, int sec0)
{
@@ -627,78 +627,78 @@ ydhms64_diff (long_int year1, long_int yday1, int hour1, int min1, int sec1,
int b400 = SHR (b100, 2);
int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
- /* Compute the desired time in time64_t precision. Overflow might
+ /* Compute the desired time in __time64_t precision. Overflow might
occur here. */
- time64_t tyear1 = year1;
- time64_t years = tyear1 - year0;
- time64_t days = 365 * years + yday1 - yday0 + intervening_leap_days;
- time64_t hours = 24 * days + hour1 - hour0;
- time64_t minutes = 60 * hours + min1 - min0;
- time64_t seconds = 60 * minutes + sec1 - sec0;
+ __time64_t tyear1 = year1;
+ __time64_t years = tyear1 - year0;
+ __time64_t days = 365 * years + yday1 - yday0 + intervening_leap_days;
+ __time64_t hours = 24 * days + hour1 - hour0;
+ __time64_t minutes = 60 * hours + min1 - min0;
+ __time64_t seconds = 60 * minutes + sec1 - sec0;
return seconds;
}
/* Return the average of A and B, even if A + B would overflow. */
-static time64_t
-time64_t_avg (time64_t a, time64_t b)
+static __time64_t
+time64_t_avg (__time64_t a, __time64_t b)
{
return SHR (a, 1) + SHR (b, 1) + (a & b & 1);
}
-/* Return 1 if A + B does not overflow. If time64_t is unsigned and if
- B's top bit is set, assume that the sum represents A - -B, and
+/* Return 1 if A + B does not overflow. If __time64_t is unsigned and
+ if B's top bit is set, assume that the sum represents A - -B, and
return 1 if the subtraction does not wrap around. */
static int
-time64_t_add_ok (time64_t a, time64_t b)
+time64_t_add_ok (__time64_t a, __time64_t b)
{
- if (! TYPE_SIGNED (time64_t))
+ if (! TYPE_SIGNED (__time64_t))
{
- time64_t sum = a + b;
+ __time64_t sum = a + b;
return (sum < a) == (TIME_T_MIDPOINT <= b);
}
else if (WRAPV)
{
- time64_t sum = a + b;
+ __time64_t sum = a + b;
return (sum < a) == (b < 0);
}
else
{
- time64_t avg = time64_t_avg (a, b);
+ __time64_t avg = time64_t_avg (a, b);
return TIME_T_MIN / 2 <= avg && avg <= TIME_T_MAX / 2;
}
}
/* Return 1 if A + B does not overflow. */
static int
-time64_t_int_add_ok (time64_t a, int b)
+time64_t_int_add_ok (__time64_t a, int b)
{
verify (int_no_wider_than_time64_t, INT_MAX <= TIME_T_MAX);
if (WRAPV)
{
- time64_t sum = a + b;
+ __time64_t sum = a + b;
return (sum < a) == (b < 0);
}
else
{
int a_odd = a & 1;
- time64_t avg = SHR (a, 1) + (SHR (b, 1) + (a_odd & b));
+ __time64_t avg = SHR (a, 1) + (SHR (b, 1) + (a_odd & b));
return TIME_T_MIN / 2 <= avg && avg <= TIME_T_MAX / 2;
}
}
-/* Return a time64_t value corresponding to (YEAR-YDAY HOUR:MIN:SEC),
+/* Return a __time64_t value corresponding to (YEAR-YDAY HOUR:MIN:SEC),
assuming that *T corresponds to *TP and that no clock adjustments
occurred between *TP and the desired time.
If TP is null, return a value not equal to *T; this avoids false matches.
If overflow occurs, yield the minimal or maximal value, except do not
yield a value equal to *T. */
-static time64_t
+static __time64_t
guess_time64_tm (long_int year, long_int yday, int hour, int min, int sec,
- const time64_t *t, const struct tm *tp)
+ const __time64_t *t, const struct tm *tp)
{
if (tp)
{
- time64_t d = ydhms64_diff (year, yday, hour, min, sec,
+ __time64_t d = ydhms64_diff (year, yday, hour, min, sec,
tp->tm_year, tp->tm_yday,
tp->tm_hour, tp->tm_min, tp->tm_sec);
if (time64_t_add_ok (*t, d))
@@ -719,22 +719,22 @@ guess_time64_tm (long_int year, long_int yday, int hour, int min, int sec,
If *T is out of range for conversion, adjust it so that
it is the nearest in-range value and then convert that. */
static struct tm *
-ranged64_convert (struct tm *(*convert) (const time64_t *, struct tm *),
- time64_t *t, struct tm *tp)
+ranged64_convert (struct tm *(*convert) (const __time64_t *, struct tm *),
+ __time64_t *t, struct tm *tp)
{
struct tm *r = convert (t, tp);
if (!r && *t)
{
- time64_t bad = *t;
- time64_t ok = 0;
+ __time64_t bad = *t;
+ __time64_t ok = 0;
- /* BAD is a known unconvertible time64_t, and OK is a known good one.
- Use binary search to narrow the range between BAD and OK until
- they differ by 1. */
+ /* BAD is a known unconvertible __time64_t, and OK is a known good
+ one. Use binary search to narrow the range between BAD and OK
+ until they differ by 1. */
while (bad != ok + (bad < 0 ? -1 : 1))
{
- time64_t mid = *t = time64_t_avg (ok, bad);
+ __time64_t mid = *t = time64_t_avg (ok, bad);
r = convert (t, tp);
if (r)
ok = mid;
@@ -755,18 +755,18 @@ ranged64_convert (struct tm *(*convert) (const time64_t *, struct tm *),
}
-/* Convert *TP to a time64_t value, inverting
+/* Convert *TP to a __time64_t value, inverting
the monotonic and mostly-unit-linear conversion function CONVERT.
Use *OFFSET to keep track of a guess at the offset of the result,
compared to what the result would be for UTC without leap seconds.
If *OFFSET's guess is correct, only one CONVERT call is needed.
This function is external because it is used also by timegm.c. */
-time64_t
+__time64_t
__mktime64_internal (struct tm *tp,
- struct tm *(*convert) (const time64_t *, struct tm *),
- time64_t *offset)
+ struct tm *(*convert) (const __time64_t *, struct tm *),
+ __time64_t *offset)
{
- time64_t t, gt, t0, t1, t2;
+ __time64_t t, gt, t0, t1, t2;
struct tm tm;
/* The maximum number of probes (calls to CONVERT) should be enough
@@ -797,7 +797,7 @@ __mktime64_internal (struct tm *tp,
/* The other values need not be in range:
the remaining code handles minor overflows correctly,
- assuming int and time64_t arithmetic wraps around.
+ assuming int and __time64_t arithmetic wraps around.
Major overflows are caught at the end. */
/* Calculate day of year from year, month, and day of month.
@@ -808,7 +808,7 @@ __mktime64_internal (struct tm *tp,
long_int lmday = mday;
long_int yday = mon_yday + lmday;
- time64_t guessed_offset = *offset;
+ __time64_t guessed_offset = *offset;
int sec_requested = sec;
@@ -830,7 +830,7 @@ __mktime64_internal (struct tm *tp,
if (TIME_T_MAX / INT_MAX / 366 / 24 / 60 / 60 < 3)
{
- /* time64_t isn't large enough to rule out overflows, so check
+ /* __time64_t isn't large enough to rule out overflows, so check
for major overflows. A gross check suffices, since if t0
has overflowed, it is off by a multiple of TIME_T_MAX -
TIME_T_MIN + 1. So ignore any component of the difference
@@ -866,16 +866,16 @@ __mktime64_internal (struct tm *tp,
gives a positive value of 715827882. Setting a variable
first then doing math on it seems to work.
(ghazi@caip.rutgers.edu) */
- time64_t time64_t_max = TIME_T_MAX;
- time64_t time64_t_min = TIME_T_MIN;
- time64_t overflow_threshold =
+ __time64_t time64_t_max = TIME_T_MAX;
+ __time64_t time64_t_min = TIME_T_MIN;
+ __time64_t overflow_threshold =
(time64_t_max / 3 - time64_t_min / 3) >> ALOG2_SECONDS_PER_BIENNIUM;
if (overflow_threshold < approx_abs_diff)
{
/* Overflow occurred. Try repairing it; this might work if
the time zone offset is enough to undo the overflow. */
- time64_t repaired_t0 = -1 - t0;
+ __time64_t repaired_t0 = -1 - t0;
approx_biennia = SHR (repaired_t0, ALOG2_SECONDS_PER_BIENNIUM);
diff = approx_biennia - approx_requested_biennia;
approx_abs_diff = diff < 0 ? -1 - diff : diff;
@@ -948,7 +948,7 @@ __mktime64_internal (struct tm *tp,
for (direction = -1; direction <= 1; direction += 2)
if (time64_t_int_add_ok (t, delta * direction))
{
- time64_t ot = t + delta * direction;
+ __time64_t ot = t + delta * direction;
struct tm otm;
ranged64_convert (convert, &ot, &otm);
if (! isdst_differ (isdst, otm.tm_isdst))
@@ -990,10 +990,10 @@ __mktime64_internal (struct tm *tp,
offset in seconds. 'int' should be good enough for GNU code. We
can't fix this unilaterally though, as other modules invoke
__mktime_internal. */
-static time64_t localtime64_offset;
+static __time64_t localtime64_offset;
-/* Convert *TP to a time64_t value. */
-time64_t
+/* Convert *TP to a __time64_t value. */
+__time64_t
mktime64 (struct tm *tp)
{
#ifdef _LIBC
diff --git a/time/offtime.c b/time/offtime.c
index d295214..84237db 100644
--- a/time/offtime.c
+++ b/time/offtime.c
@@ -90,9 +90,9 @@ __offtime (const time_t *t, long int offset, struct tm *tp)
and store year, yday, mon, mday, wday, hour, min, sec into *TP.
Return nonzero if successful. */
int
-__offtime64 (const time64_t *t, long int offset, struct tm *tp)
+__offtime64 (const __time64_t *t, long int offset, struct tm *tp)
{
- time64_t days, rem, y;
+ __time64_t days, rem, y;
const unsigned short int *ip;
days = *t / SECS_PER_DAY;
@@ -124,7 +124,7 @@ __offtime64 (const time64_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. */
- time64_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
diff --git a/time/time.h b/time/time.h
index dc0da15..fa92275 100644
--- a/time/time.h
+++ b/time/time.h
@@ -73,14 +73,14 @@ __BEGIN_NAMESPACE_STD
extern clock_t clock (void) __THROW;
/* Return the current time and put it in *TIMER if TIMER is not NULL. */
-extern time_t time (time_t *__timer) __THROW;
+extern __time_t time (__time_t *__timer) __THROW;
/* Return the difference between TIME1 and TIME0. */
-extern double difftime (time_t __time1, time_t __time0)
+extern double difftime (__time_t __time1,__time_t __time0)
__THROW __attribute__ ((__const__));
/* Return the difference between TIME1 and TIME0. */
-extern double difftime64 (time64_t __time1, time64_t __time0)
+extern double difftime64 (__time64_t __time1, __time64_t __time0)
__THROW __attribute__ ((__const__));
#ifdef __USE_TIME_BITS64
@@ -88,10 +88,10 @@ extern double difftime64 (time64_t __time1, time64_t __time0)
#endif
/* Return the `time_t' representation of TP and normalize TP. */
-extern time_t mktime (struct tm *__tp) __THROW;
+extern __time_t mktime (struct tm *__tp) __THROW;
-/* Return the `time64_t' representation of TP and normalize TP. */
-extern time64_t mktime64 (struct tm *__tp) __THROW;
+/* Return the `__time64_t' representation of TP and normalize TP. */
+extern __time64_t mktime64 (struct tm *__tp) __THROW;
/* Format TP into S according to FORMAT.
Write no more than MAXSIZE characters and return the number
@@ -129,11 +129,11 @@ extern char *strptime_l (const char *__restrict __s,
__BEGIN_NAMESPACE_STD
/* Return the `struct tm' representation of *TIMER
in Universal Coordinated Time (aka Greenwich Mean Time). */
-extern struct tm *gmtime (const time_t *__timer) __THROW;
+extern struct tm *gmtime (const __time_t *__timer) __THROW;
/* Return the `struct tm' representation of 64-bit-time *TIMER
in Universal Coordinated Time (aka Greenwich Mean Time). */
-extern struct tm *gmtime64 (const time64_t *__timer) __THROW;
+extern struct tm *gmtime64 (const __time64_t *__timer) __THROW;
#ifdef __USE_TIME_BITS64
#define gmtime gmtime64
@@ -141,11 +141,11 @@ extern struct tm *gmtime64 (const time64_t *__timer) __THROW;
/* Return the `struct tm' representation
of *TIMER in the local timezone. */
-extern struct tm *localtime (const time_t *__timer) __THROW;
+extern struct tm *localtime (const __time_t *__timer) __THROW;
/* Return the `struct tm' representation
of the 64-bit-time *TIMER in the local timezone. */
-extern struct tm *localtime64 (const time64_t *__timer) __THROW;
+extern struct tm *localtime64 (const __time64_t *__timer) __THROW;
#ifdef __USE_TIME_BITS64
#define localtime localtime64
@@ -155,12 +155,12 @@ __END_NAMESPACE_STD
#ifdef __USE_POSIX
/* Return the `struct tm' representation of *TIMER in UTC,
using *TP to store the result. */
-extern struct tm *gmtime_r (const time_t *__restrict __timer,
+extern struct tm *gmtime_r (const __time_t *__restrict __timer,
struct tm *__restrict __tp) __THROW;
/* Return the `struct tm' representation of 64-bit-time *TIMER
in UTC, using *TP to store the result. */
-extern struct tm *gmtime64_r (const time64_t *__restrict __timer,
+extern struct tm *gmtime64_r (const __time64_t *__restrict __timer,
struct tm *__restrict __tp) __THROW;
#ifdef __USE_TIME_BITS64
@@ -169,12 +169,12 @@ extern struct tm *gmtime64_r (const time64_t *__restrict __timer,
/* Return the `struct tm' representation of *TIMER in local time,
using *TP to store the result. */
-extern struct tm *localtime_r (const time_t *__restrict __timer,
+extern struct tm *localtime_r (const __time_t *__restrict __timer,
struct tm *__restrict __tp) __THROW;
/* Return the `struct tm' representation of the 64-bit-time *TIMER
in local time, using *TP to store the result. */
-extern struct tm *localtime64_r (const time64_t *__restrict __timer,
+extern struct tm *localtime64_r (const __time64_t *__restrict __timer,
struct tm *__restrict __tp) __THROW;
#ifdef __USE_TIME_BITS64
@@ -184,16 +184,18 @@ extern struct tm *localtime64_r (const time64_t *__restrict __timer,
#endif /* POSIX */
__BEGIN_NAMESPACE_STD
+
/* Return a string of the form "Day Mon dd hh:mm:ss yyyy\n"
that is the representation of TP in this format. */
extern char *asctime (const struct tm *__tp) __THROW;
/* Equivalent to `asctime (localtime (timer))'. */
-extern char *ctime (const time_t *__timer) __THROW;
+extern char *ctime (const __time_t *__timer) __THROW;
/* Equivalent to `asctime (localtime64 (timer))'. */
-extern char *ctime64 (const time64_t *__timer) __THROW;
+extern char *ctime64 (const __time64_t *__timer) __THROW;
+/* If defaulting to 64-bit time, override 32-bit symbols */
#ifdef __USE_TIME_BITS64
#define ctime ctime64
#endif
@@ -209,7 +211,7 @@ extern char *asctime_r (const struct tm *__restrict __tp,
char *__restrict __buf) __THROW;
/* Equivalent to `asctime_r (localtime_r (timer, *TMP*), buf)'. */
-extern char *ctime_r (const time_t *__restrict __timer,
+extern char *ctime_r (const __time_t *__restrict __timer,
char *__restrict __buf) __THROW;
#endif /* POSIX */
@@ -237,7 +239,7 @@ extern long int timezone;
#ifdef __USE_MISC
/* Set the system time to *WHEN.
This call is restricted to the superuser. */
-extern int stime (const time_t *__when) __THROW;
+extern int stime (const __time_t *__when) __THROW;
#endif
@@ -252,13 +254,13 @@ extern int stime (const time_t *__when) __THROW;
localtime package. These are included only for compatibility. */
/* Like `mktime', but for TP represents Universal Time, not local time. */
-extern time_t timegm (struct tm *__tp) __THROW;
+extern __time_t timegm (struct tm *__tp) __THROW;
/* Another name for `mktime'. */
-extern time_t timelocal (struct tm *__tp) __THROW;
+extern __time_t timelocal (struct tm *__tp) __THROW;
/* Another name for `mktime64'. */
-extern time64_t timelocal64 (struct tm *__tp) __THROW;
+extern __time64_t timelocal64 (struct tm *__tp) __THROW;
/* Return the number of days in YEAR. */
extern int dysize (int __year) __THROW __attribute__ ((__const__));
diff --git a/time/tzfile.c b/time/tzfile.c
index f4642e7..9d1a0f6 100644
--- a/time/tzfile.c
+++ b/time/tzfile.c
@@ -637,7 +637,7 @@ __tzfile_default (const char *std, const char *dst,
}
void
-__tzfile_compute (time64_t timer, int use_localtime,
+__tzfile_compute (__time64_t timer, int use_localtime,
long int *leap_correct, int *leap_hit,
struct tm *tp)
{
diff --git a/time/tzset.c b/time/tzset.c
index 3f6b7bf..954e248 100644
--- a/time/tzset.c
+++ b/time/tzset.c
@@ -61,7 +61,7 @@ typedef struct
/* We cache the computed time of change for a
given year so we don't have to recompute it. */
- time64_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;
@@ -451,7 +451,7 @@ tzset_internal (int always, int explicit)
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 = (time64_t) -1;
+ tz_rules[0].change = tz_rules[1].change = (__time64_t) -1;
update_vars ();
return;
}
@@ -551,10 +551,11 @@ compute_change (tz_rule *rule, int year)
/* Figure out the correct timezone for TM and set `__tzname',
`__timezone', and `__daylight' accordingly.
- NOTE: this takes a time64_t value, so passing a time_t value is OK. */
+ NOTE: this takes a __time64_t value, so passing a __time_t value
+ is OK. */
void
internal_function
-__tz_compute (time64_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);
@@ -658,7 +659,7 @@ __tz_convert (const time_t *timer, int use_localtime, struct tm *tp)
/* Return the `struct tm' representation of *TIMER in the local timezone.
Use local time if USE_LOCALTIME is nonzero, UTC otherwise. */
struct tm *
-__tz64_convert (const time64_t *timer, int use_localtime, struct tm *tp)
+__tz64_convert (const __time64_t *timer, int use_localtime, struct tm *tp)
{
long int leap_correction;
int leap_extra_secs;
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=f639a0d4a2ba7e22070c0176673e39159dbf2017
commit f639a0d4a2ba7e22070c0176673e39159dbf2017
Author: Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
Date: Tue Feb 7 22:21:14 2017 +0100
Add 64-bit versions of mktime and timelocal
diff --git a/include/time.h b/include/time.h
index ed5440b..524d3ec 100644
--- a/include/time.h
+++ b/include/time.h
@@ -13,7 +13,9 @@ extern __typeof (strptime_l) __strptime_l;
libc_hidden_proto (time)
libc_hidden_proto (asctime)
libc_hidden_proto (mktime)
+libc_hidden_proto (mktime64)
libc_hidden_proto (timelocal)
+libc_hidden_proto (timelocal64)
libc_hidden_proto (localtime)
libc_hidden_proto (localtime64)
libc_hidden_proto (strftime)
@@ -65,6 +67,15 @@ extern time_t __mktime_internal (struct tm *__tp,
struct tm *(*__func) (const time_t *,
struct tm *),
time_t *__offset);
+
+/* Subroutine of `mktime64'. Return the `time64_t' representation of TP and
+ normalize TP, given that a `struct tm *' maps to a `time64_t' as performed
+ by FUNC. Keep track of next guess for time64_t offset in *OFFSET. */
+extern time64_t __mktime64_internal (struct tm *__tp,
+ struct tm *(*__func) (const time64_t *,
+ struct tm *),
+ time64_t *__offset);
+
extern struct tm *__localtime_r (const time_t *__timer,
struct tm *__tp) attribute_hidden;
diff --git a/sysdeps/unix/sysv/linux/arm/Versions b/sysdeps/unix/sysv/linux/arm/Versions
index 3fbf0fe..7b8ee8d 100644
--- a/sysdeps/unix/sysv/linux/arm/Versions
+++ b/sysdeps/unix/sysv/linux/arm/Versions
@@ -14,7 +14,9 @@ libc {
clock_gettime64; clock_settime64;
ctime64; difftime64;
gmtime64; gmtime64_r;
- localtime64; localtime64_r;
+ localtime64; localtime64_r;
+ mktime64;
+ timelocal64;
}
GLIBC_PRIVATE {
# A copy of sigaction lives in libpthread, and needs these.
diff --git a/time/mktime.c b/time/mktime.c
index 4c48d35..b47b969 100644
--- a/time/mktime.c
+++ b/time/mktime.c
@@ -599,6 +599,421 @@ weak_alias (mktime, timelocal)
libc_hidden_def (mktime)
libc_hidden_weak (timelocal)
#endif
+
+/* Return an integer value measuring (YEAR1-YDAY1 HOUR1:MIN1:SEC1) -
+ (YEAR0-YDAY0 HOUR0:MIN0:SEC0) in seconds, assuming that the clocks
+ were not adjusted between the time stamps.
+
+ The YEAR values uses the same numbering as TP->tm_year. Values
+ need not be in the usual range. However, YEAR1 must not be less
+ than 2 * INT_MIN or greater than 2 * INT_MAX.
+
+ The result may overflow. It is the caller's responsibility to
+ detect overflow. */
+
+static time64_t
+ydhms64_diff (long_int year1, long_int yday1, int hour1, int min1, int sec1,
+ int year0, int yday0, int hour0, int min0, int sec0)
+{
+ verify (C99_integer_division, -1 / 2 == 0);
+
+ /* Compute intervening leap days correctly even if year is negative.
+ Take care to avoid integer overflow here. */
+ int a4 = SHR (year1, 2) + SHR (TM_YEAR_BASE, 2) - ! (year1 & 3);
+ int b4 = SHR (year0, 2) + SHR (TM_YEAR_BASE, 2) - ! (year0 & 3);
+ int a100 = a4 / 25 - (a4 % 25 < 0);
+ int b100 = b4 / 25 - (b4 % 25 < 0);
+ int a400 = SHR (a100, 2);
+ int b400 = SHR (b100, 2);
+ int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
+
+ /* Compute the desired time in time64_t precision. Overflow might
+ occur here. */
+ time64_t tyear1 = year1;
+ time64_t years = tyear1 - year0;
+ time64_t days = 365 * years + yday1 - yday0 + intervening_leap_days;
+ time64_t hours = 24 * days + hour1 - hour0;
+ time64_t minutes = 60 * hours + min1 - min0;
+ time64_t seconds = 60 * minutes + sec1 - sec0;
+ return seconds;
+}
+
+/* Return the average of A and B, even if A + B would overflow. */
+static time64_t
+time64_t_avg (time64_t a, time64_t b)
+{
+ return SHR (a, 1) + SHR (b, 1) + (a & b & 1);
+}
+
+/* Return 1 if A + B does not overflow. If time64_t is unsigned and if
+ B's top bit is set, assume that the sum represents A - -B, and
+ return 1 if the subtraction does not wrap around. */
+static int
+time64_t_add_ok (time64_t a, time64_t b)
+{
+ if (! TYPE_SIGNED (time64_t))
+ {
+ time64_t sum = a + b;
+ return (sum < a) == (TIME_T_MIDPOINT <= b);
+ }
+ else if (WRAPV)
+ {
+ time64_t sum = a + b;
+ return (sum < a) == (b < 0);
+ }
+ else
+ {
+ time64_t avg = time64_t_avg (a, b);
+ return TIME_T_MIN / 2 <= avg && avg <= TIME_T_MAX / 2;
+ }
+}
+
+/* Return 1 if A + B does not overflow. */
+static int
+time64_t_int_add_ok (time64_t a, int b)
+{
+ verify (int_no_wider_than_time64_t, INT_MAX <= TIME_T_MAX);
+ if (WRAPV)
+ {
+ time64_t sum = a + b;
+ return (sum < a) == (b < 0);
+ }
+ else
+ {
+ int a_odd = a & 1;
+ time64_t avg = SHR (a, 1) + (SHR (b, 1) + (a_odd & b));
+ return TIME_T_MIN / 2 <= avg && avg <= TIME_T_MAX / 2;
+ }
+}
+
+/* Return a time64_t value corresponding to (YEAR-YDAY HOUR:MIN:SEC),
+ assuming that *T corresponds to *TP and that no clock adjustments
+ occurred between *TP and the desired time.
+ If TP is null, return a value not equal to *T; this avoids false matches.
+ If overflow occurs, yield the minimal or maximal value, except do not
+ yield a value equal to *T. */
+static time64_t
+guess_time64_tm (long_int year, long_int yday, int hour, int min, int sec,
+ const time64_t *t, const struct tm *tp)
+{
+ if (tp)
+ {
+ time64_t d = ydhms64_diff (year, yday, hour, min, sec,
+ tp->tm_year, tp->tm_yday,
+ tp->tm_hour, tp->tm_min, tp->tm_sec);
+ if (time64_t_add_ok (*t, d))
+ return *t + d;
+ }
+
+ /* Overflow occurred one way or another. Return the nearest result
+ that is actually in range, except don't report a zero difference
+ if the actual difference is nonzero, as that would cause a false
+ match; and don't oscillate between two values, as that would
+ confuse the spring-forward gap detector. */
+ return (*t < TIME_T_MIDPOINT
+ ? (*t <= TIME_T_MIN + 1 ? *t + 1 : TIME_T_MIN)
+ : (TIME_T_MAX - 1 <= *t ? *t - 1 : TIME_T_MAX));
+}
+
+/* Use CONVERT to convert *T to a broken down time in *TP.
+ If *T is out of range for conversion, adjust it so that
+ it is the nearest in-range value and then convert that. */
+static struct tm *
+ranged64_convert (struct tm *(*convert) (const time64_t *, struct tm *),
+ time64_t *t, struct tm *tp)
+{
+ struct tm *r = convert (t, tp);
+
+ if (!r && *t)
+ {
+ time64_t bad = *t;
+ time64_t ok = 0;
+
+ /* BAD is a known unconvertible time64_t, and OK is a known good one.
+ Use binary search to narrow the range between BAD and OK until
+ they differ by 1. */
+ while (bad != ok + (bad < 0 ? -1 : 1))
+ {
+ time64_t mid = *t = time64_t_avg (ok, bad);
+ r = convert (t, tp);
+ if (r)
+ ok = mid;
+ else
+ bad = mid;
+ }
+
+ if (!r && ok)
+ {
+ /* The last conversion attempt failed;
+ revert to the most recent successful attempt. */
+ *t = ok;
+ r = convert (t, tp);
+ }
+ }
+
+ return r;
+}
+
+
+/* Convert *TP to a time64_t value, inverting
+ the monotonic and mostly-unit-linear conversion function CONVERT.
+ Use *OFFSET to keep track of a guess at the offset of the result,
+ compared to what the result would be for UTC without leap seconds.
+ If *OFFSET's guess is correct, only one CONVERT call is needed.
+ This function is external because it is used also by timegm.c. */
+time64_t
+__mktime64_internal (struct tm *tp,
+ struct tm *(*convert) (const time64_t *, struct tm *),
+ time64_t *offset)
+{
+ time64_t t, gt, t0, t1, t2;
+ struct tm tm;
+
+ /* The maximum number of probes (calls to CONVERT) should be enough
+ to handle any combinations of time zone rule changes, solar time,
+ leap seconds, and oscillations around a spring-forward gap.
+ POSIX.1 prohibits leap seconds, but some hosts have them anyway. */
+ int remaining_probes = 6;
+
+ /* Time requested. Copy it in case CONVERT modifies *TP; this can
+ occur if TP is localtime's returned value and CONVERT is localtime. */
+ int sec = tp->tm_sec;
+ int min = tp->tm_min;
+ int hour = tp->tm_hour;
+ int mday = tp->tm_mday;
+ int mon = tp->tm_mon;
+ int year_requested = tp->tm_year;
+ int isdst = tp->tm_isdst;
+
+ /* 1 if the previous probe was DST. */
+ int dst2;
+
+ /* Ensure that mon is in range, and set year accordingly. */
+ int mon_remainder = mon % 12;
+ int negative_mon_remainder = mon_remainder < 0;
+ int mon_years = mon / 12 - negative_mon_remainder;
+ long_int lyear_requested = year_requested;
+ long_int year = lyear_requested + mon_years;
+
+ /* The other values need not be in range:
+ the remaining code handles minor overflows correctly,
+ assuming int and time64_t arithmetic wraps around.
+ Major overflows are caught at the end. */
+
+ /* Calculate day of year from year, month, and day of month.
+ The result need not be in range. */
+ int mon_yday = ((__mon_yday[leapyear (year)]
+ [mon_remainder + 12 * negative_mon_remainder])
+ - 1);
+ long_int lmday = mday;
+ long_int yday = mon_yday + lmday;
+
+ time64_t guessed_offset = *offset;
+
+ int sec_requested = sec;
+
+ if (LEAP_SECONDS_POSSIBLE)
+ {
+ /* Handle out-of-range seconds specially,
+ since ydhms_tm_diff assumes every minute has 60 seconds. */
+ if (sec < 0)
+ sec = 0;
+ if (59 < sec)
+ sec = 59;
+ }
+
+ /* Invert CONVERT by probing. First assume the same offset as last
+ time. */
+
+ t0 = ydhms64_diff (year, yday, hour, min, sec,
+ EPOCH_YEAR - TM_YEAR_BASE, 0, 0, 0, - guessed_offset);
+
+ if (TIME_T_MAX / INT_MAX / 366 / 24 / 60 / 60 < 3)
+ {
+ /* time64_t isn't large enough to rule out overflows, so check
+ for major overflows. A gross check suffices, since if t0
+ has overflowed, it is off by a multiple of TIME_T_MAX -
+ TIME_T_MIN + 1. So ignore any component of the difference
+ that is bounded by a small value. */
+
+ /* Approximate log base 2 of the number of time units per
+ biennium. A biennium is 2 years; use this unit instead of
+ years to avoid integer overflow. For example, 2 average
+ Gregorian years are 2 * 365.2425 * 24 * 60 * 60 seconds,
+ which is 63113904 seconds, and rint (log2 (63113904)) is
+ 26. */
+ int ALOG2_SECONDS_PER_BIENNIUM = 26;
+ int ALOG2_MINUTES_PER_BIENNIUM = 20;
+ int ALOG2_HOURS_PER_BIENNIUM = 14;
+ int ALOG2_DAYS_PER_BIENNIUM = 10;
+ int LOG2_YEARS_PER_BIENNIUM = 1;
+
+ int approx_requested_biennia =
+ (SHR (year_requested, LOG2_YEARS_PER_BIENNIUM)
+ - SHR (EPOCH_YEAR - TM_YEAR_BASE, LOG2_YEARS_PER_BIENNIUM)
+ + SHR (mday, ALOG2_DAYS_PER_BIENNIUM)
+ + SHR (hour, ALOG2_HOURS_PER_BIENNIUM)
+ + SHR (min, ALOG2_MINUTES_PER_BIENNIUM)
+ + (LEAP_SECONDS_POSSIBLE
+ ? 0
+ : SHR (sec, ALOG2_SECONDS_PER_BIENNIUM)));
+
+ int approx_biennia = SHR (t0, ALOG2_SECONDS_PER_BIENNIUM);
+ int diff = approx_biennia - approx_requested_biennia;
+ int approx_abs_diff = diff < 0 ? -1 - diff : diff;
+
+ /* IRIX 4.0.5 cc miscalculates TIME_T_MIN / 3: it erroneously
+ gives a positive value of 715827882. Setting a variable
+ first then doing math on it seems to work.
+ (ghazi@caip.rutgers.edu) */
+ time64_t time64_t_max = TIME_T_MAX;
+ time64_t time64_t_min = TIME_T_MIN;
+ time64_t overflow_threshold =
+ (time64_t_max / 3 - time64_t_min / 3) >> ALOG2_SECONDS_PER_BIENNIUM;
+
+ if (overflow_threshold < approx_abs_diff)
+ {
+ /* Overflow occurred. Try repairing it; this might work if
+ the time zone offset is enough to undo the overflow. */
+ time64_t repaired_t0 = -1 - t0;
+ approx_biennia = SHR (repaired_t0, ALOG2_SECONDS_PER_BIENNIUM);
+ diff = approx_biennia - approx_requested_biennia;
+ approx_abs_diff = diff < 0 ? -1 - diff : diff;
+ if (overflow_threshold < approx_abs_diff)
+ return -1;
+ guessed_offset += repaired_t0 - t0;
+ t0 = repaired_t0;
+ }
+ }
+
+ /* Repeatedly use the error to improve the guess. */
+
+ for (t = t1 = t2 = t0, dst2 = 0;
+ (gt = guess_time64_tm (year, yday, hour, min, sec, &t,
+ ranged64_convert (convert, &t, &tm)),
+ t != gt);
+ t1 = t2, t2 = t, t = gt, dst2 = tm.tm_isdst != 0)
+ if (t == t1 && t != t2
+ && (tm.tm_isdst < 0
+ || (isdst < 0
+ ? dst2 <= (tm.tm_isdst != 0)
+ : (isdst != 0) != (tm.tm_isdst != 0))))
+ /* We can't possibly find a match, as we are oscillating
+ between two values. The requested time probably falls
+ within a spring-forward gap of size GT - T. Follow the common
+ practice in this case, which is to return a time that is GT - T
+ away from the requested time, preferring a time whose
+ tm_isdst differs from the requested value. (If no tm_isdst
+ was requested and only one of the two values has a nonzero
+ tm_isdst, prefer that value.) In practice, this is more
+ useful than returning -1. */
+ goto offset_found;
+ else if (--remaining_probes == 0)
+ return -1;
+
+ /* We have a match. Check whether tm.tm_isdst has the requested
+ value, if any. */
+ if (isdst_differ (isdst, tm.tm_isdst))
+ {
+ /* tm.tm_isdst has the wrong value. Look for a neighboring
+ time with the right value, and use its UTC offset.
+
+ Heuristic: probe the adjacent timestamps in both directions,
+ looking for the desired isdst. This should work for all real
+ time zone histories in the tz database. */
+
+ /* Distance between probes when looking for a DST boundary. In
+ tzdata2003a, the shortest period of DST is 601200 seconds
+ (e.g., America/Recife starting 2000-10-08 01:00), and the
+ shortest period of non-DST surrounded by DST is 694800
+ seconds (Africa/Tunis starting 1943-04-17 01:00). Use the
+ minimum of these two values, so we don't miss these short
+ periods when probing. */
+ int stride = 601200;
+
+ /* The longest period of DST in tzdata2003a is 536454000 seconds
+ (e.g., America/Jujuy starting 1946-10-01 01:00). The longest
+ period of non-DST is much longer, but it makes no real sense
+ to search for more than a year of non-DST, so use the DST
+ max. */
+ int duration_max = 536454000;
+
+ /* Search in both directions, so the maximum distance is half
+ the duration; add the stride to avoid off-by-1 problems. */
+ int delta_bound = duration_max / 2 + stride;
+
+ int delta, direction;
+
+ for (delta = stride; delta < delta_bound; delta += stride)
+ for (direction = -1; direction <= 1; direction += 2)
+ if (time64_t_int_add_ok (t, delta * direction))
+ {
+ time64_t ot = t + delta * direction;
+ struct tm otm;
+ ranged64_convert (convert, &ot, &otm);
+ if (! isdst_differ (isdst, otm.tm_isdst))
+ {
+ /* We found the desired tm_isdst.
+ Extrapolate back to the desired time. */
+ t = guess_time64_tm (year, yday, hour, min, sec, &ot, &otm);
+ ranged64_convert (convert, &t, &tm);
+ goto offset_found;
+ }
+ }
+ }
+
+ offset_found:
+ *offset = guessed_offset + t - t0;
+
+ if (LEAP_SECONDS_POSSIBLE && sec_requested != tm.tm_sec)
+ {
+ /* Adjust time to reflect the tm_sec requested, not the normalized value.
+ Also, repair any damage from a false match due to a leap second. */
+ int sec_adjustment = (sec == 0 && tm.tm_sec == 60) - sec;
+ if (! time64_t_int_add_ok (t, sec_requested))
+ return -1;
+ t1 = t + sec_requested;
+ if (! time64_t_int_add_ok (t1, sec_adjustment))
+ return -1;
+ t2 = t1 + sec_adjustment;
+ if (! convert (&t2, &tm))
+ return -1;
+ t = t2;
+ }
+
+ *tp = tm;
+ return t;
+}
+
+
+/* FIXME: This should use a signed type wide enough to hold any UTC
+ offset in seconds. 'int' should be good enough for GNU code. We
+ can't fix this unilaterally though, as other modules invoke
+ __mktime_internal. */
+static time64_t localtime64_offset;
+
+/* Convert *TP to a time64_t value. */
+time64_t
+mktime64 (struct tm *tp)
+{
+#ifdef _LIBC
+ /* POSIX.1 8.1.1 requires that whenever mktime() is called, the
+ time zone names contained in the external variable 'tzname' shall
+ be set as if the tzset() function had been called. */
+ __tzset ();
+#endif
+
+ return __mktime64_internal (tp, __localtime64_r, &localtime64_offset);
+}
+
+#ifdef weak_alias
+weak_alias (mktime64, timelocal64)
+#endif
+
+#ifdef _LIBC
+libc_hidden_def (mktime64)
+libc_hidden_weak (timelocal64)
+#endif
#if defined DEBUG_MKTIME && DEBUG_MKTIME
diff --git a/time/time.h b/time/time.h
index 2d999ed..dc0da15 100644
--- a/time/time.h
+++ b/time/time.h
@@ -90,6 +90,8 @@ extern double difftime64 (time64_t __time1, time64_t __time0)
/* Return the `time_t' representation of TP and normalize TP. */
extern time_t mktime (struct tm *__tp) __THROW;
+/* Return the `time64_t' representation of TP and normalize TP. */
+extern time64_t mktime64 (struct tm *__tp) __THROW;
/* Format TP into S according to FORMAT.
Write no more than MAXSIZE characters and return the number
@@ -255,6 +257,9 @@ extern time_t timegm (struct tm *__tp) __THROW;
/* Another name for `mktime'. */
extern time_t timelocal (struct tm *__tp) __THROW;
+/* Another name for `mktime64'. */
+extern time64_t timelocal64 (struct tm *__tp) __THROW;
+
/* Return the number of days in YEAR. */
extern int dysize (int __year) __THROW __attribute__ ((__const__));
#endif
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=0e448c7e3a7cdb18acaad9b56a493f4dd3620059
commit 0e448c7e3a7cdb18acaad9b56a493f4dd3620059
Author: Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
Date: Wed Feb 1 08:43:29 2017 +0100
Add 64-bit versions for 'broken-up time' APIs
This consists in the following API additions:
([file] 32-bit function -> [file] 64-bit variant)
time/ctime.c ctime() -> ctime64()
time/difftime.c difftime() -> difftime64()
time/gmtime.c gmtime() -> gmtime64()
time/gmtime.c gmtime_r() -> gmtime64_r()
time/localtime.c localtime() -> localtime64()
time/localtime.c localtime_r() -> localtime64_r()
which require the following internal additions
time/bits/types/time_t.h time_t -> time64_t
time/offtime.c __offtime() -> __offtime64()
time/tzset.c __tz_convert() -> __tz64_convert()
and modifications to internal functions:
time/tzfile.c __tzfile_compute()
time/tzset.c tzset_internal()
time/tzset.c compute_change()
diff --git a/include/time.h b/include/time.h
index 2fa0764..ed5440b 100644
--- a/include/time.h
+++ b/include/time.h
@@ -15,6 +15,7 @@ libc_hidden_proto (asctime)
libc_hidden_proto (mktime)
libc_hidden_proto (timelocal)
libc_hidden_proto (localtime)
+libc_hidden_proto (localtime64)
libc_hidden_proto (strftime)
libc_hidden_proto (strptime)
@@ -48,13 +49,13 @@ extern int __use_tzfile attribute_hidden;
extern void __tzfile_read (const char *file, size_t extra,
char **extrap);
-extern void __tzfile_compute (time_t timer, int use_localtime,
+extern void __tzfile_compute (time64_t timer, int use_localtime,
long int *leap_correct, int *leap_hit,
struct tm *tp);
extern void __tzfile_default (const char *std, const char *dst,
long int stdoff, long int dstoff);
extern void __tzset_parse_tz (const char *tz);
-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 internal_function;
/* Subroutine of `mktime'. Return the `time_t' representation of TP and
@@ -71,6 +72,13 @@ extern struct tm *__gmtime_r (const time_t *__restrict __timer,
struct tm *__restrict __tp);
libc_hidden_proto (__gmtime_r)
+extern struct tm *__localtime64_r (const time64_t *__timer,
+ struct tm *__tp) attribute_hidden;
+
+extern struct tm *__gmtime64_r (const time64_t *__restrict __timer,
+ struct tm *__restrict __tp);
+libc_hidden_proto (__gmtime64_r)
+
/* 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.
@@ -79,12 +87,27 @@ extern int __offtime (const time_t *__timer,
long int __offset,
struct tm *__tp);
+/* Compute the `struct tm' representation of 64-bit-time *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 __offtime64 (const time64_t *__timer,
+ long int __offset,
+ struct tm *__tp);
+
extern char *__asctime_r (const struct tm *__tp, char *__buf);
extern void __tzset (void);
/* Prototype for the internal function to get information based on TZ. */
extern struct tm *__tz_convert (const time_t *timer, int use_localtime, struct tm *tp);
+/* Prototype for the internal 64-bit-time function to get information based on TZ. */
+extern struct tm *__tz64_convert (const time64_t *timer, int use_localtime, struct tm *tp);
+
+/* Prototype for the internal function to get information based on TZ,
+ 64-bit-time version. */
+extern struct tm *__tz64_convert (const time64_t *timer, int use_localtime, struct tm *tp);
+
/* Return the maximum length of a timezone name.
This is what `sysconf (_SC_TZNAME_MAX)' does. */
extern long int __tzname_max (void);
diff --git a/sysdeps/unix/sysv/linux/arm/Versions b/sysdeps/unix/sysv/linux/arm/Versions
index 7410904..3fbf0fe 100644
--- a/sysdeps/unix/sysv/linux/arm/Versions
+++ b/sysdeps/unix/sysv/linux/arm/Versions
@@ -9,7 +9,12 @@ libc {
}
GLIBC_2.24 {
recvmsg; sendmsg;
+ }
+ GLIBC_2.25 {
clock_gettime64; clock_settime64;
+ ctime64; difftime64;
+ gmtime64; gmtime64_r;
+ localtime64; localtime64_r;
}
GLIBC_PRIVATE {
# A copy of sigaction lives in libpthread, and needs these.
diff --git a/time/bits/types/time_t.h b/time/bits/types/time_t.h
index 16e5269..906dcf9 100644
--- a/time/bits/types/time_t.h
+++ b/time/bits/types/time_t.h
@@ -11,4 +11,11 @@ __END_NAMESPACE_STD
__USING_NAMESPACE_STD(time_t)
#endif
+/* Returned by `time64'. */
+typedef __time64_t time64_t;
+__END_NAMESPACE_STD
+#ifdef __USE_POSIX
+__USING_NAMESPACE_STD(time64_t)
+#endif
+
#endif
diff --git a/time/ctime.c b/time/ctime.c
index 7baca1b..bedb08c 100644
--- a/time/ctime.c
+++ b/time/ctime.c
@@ -26,3 +26,13 @@ ctime (const time_t *t)
In particular, ctime and asctime must yield the same pointer. */
return asctime (localtime (t));
}
+
+/* Return a string as returned by asctime which
+ is the representation of *T in that form. */
+char *
+ctime64 (const time64_t *t)
+{
+ /* Apply the same rule as ctime:
+ make ctime64 (t) is equivalent to asctime (localtime64 (t)). */
+ return asctime (localtime64 (t));
+}
diff --git a/time/difftime.c b/time/difftime.c
index e5e3311..47ed6e1 100644
--- a/time/difftime.c
+++ b/time/difftime.c
@@ -119,3 +119,14 @@ __difftime (time_t time1, time_t time0)
return time1 < time0 ? - subtract (time0, time1) : subtract (time1, time0);
}
strong_alias (__difftime, difftime)
+
+/* Return the difference between 64-bit TIME1 and TIME0. */
+double
+__difftime64 (time64_t time1, time64_t time0)
+{
+ /* Subtract the smaller integer from the larger, convert the difference to
+ double, and then negate if needed. */
+
+ return time1 < time0 ? - (time0 - time1) : (time1 - time0);
+}
+strong_alias (__difftime64, difftime64)
diff --git a/time/gmtime.c b/time/gmtime.c
index 049d551..3eefeb5 100644
--- a/time/gmtime.c
+++ b/time/gmtime.c
@@ -35,3 +35,21 @@ gmtime (const time_t *t)
{
return __tz_convert (t, 0, &_tmbuf);
}
+
+/* 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 __tz64_convert (t, 0, tp);
+}
+libc_hidden_def (__gmtime64_r)
+weak_alias (__gmtime64_r, gmtime64_r)
+
+
+/* Return the `struct tm' representation of 64-bit-time *T in UTC. */
+struct tm *
+gmtime64 (const time64_t *t)
+{
+ return __tz64_convert (t, 0, &_tmbuf);
+}
diff --git a/time/localtime.c b/time/localtime.c
index 07dd67c..8310aef 100644
--- a/time/localtime.c
+++ b/time/localtime.c
@@ -39,3 +39,23 @@ localtime (const time_t *t)
return __tz_convert (t, 1, &_tmbuf);
}
libc_hidden_def (localtime)
+
+/* 64-bit-time versions */
+
+/* Return the `struct tm' representation of *T in local time,
+ using *TP to store the result. */
+struct tm *
+__localtime64_r (const time64_t *t, struct tm *tp)
+{
+ return __tz64_convert (t, 1, tp);
+}
+weak_alias (__localtime64_r, localtime64_r)
+
+
+/* Return the `struct tm' representation of *T in local time. */
+struct tm *
+localtime64 (const time64_t *t)
+{
+ return __tz64_convert (t, 1, &_tmbuf);
+}
+libc_hidden_def (localtime64)
diff --git a/time/offtime.c b/time/offtime.c
index 75a28fe..d295214 100644
--- a/time/offtime.c
+++ b/time/offtime.c
@@ -84,3 +84,67 @@ __offtime (const time_t *t, long int offset, struct tm *tp)
tp->tm_mday = days + 1;
return 1;
}
+
+/* Compute the `struct tm' representation of 64-bit-time *T,
+ offset OFFSET seconds east of UTC,
+ and store year, yday, mon, mday, wday, hour, min, sec into *TP.
+ Return nonzero if successful. */
+int
+__offtime64 (const time64_t *t, long int offset, struct tm *tp)
+{
+ time64_t days, rem, y;
+ const unsigned short int *ip;
+
+ days = *t / SECS_PER_DAY;
+ rem = *t % SECS_PER_DAY;
+ rem += offset;
+ while (rem < 0)
+ {
+ rem += SECS_PER_DAY;
+ --days;
+ }
+ while (rem >= SECS_PER_DAY)
+ {
+ rem -= SECS_PER_DAY;
+ ++days;
+ }
+ tp->tm_hour = rem / SECS_PER_HOUR;
+ rem %= SECS_PER_HOUR;
+ tp->tm_min = rem / 60;
+ tp->tm_sec = rem % 60;
+ /* January 1, 1970 was a Thursday. */
+ tp->tm_wday = (4 + days) % 7;
+ if (tp->tm_wday < 0)
+ tp->tm_wday += 7;
+ y = 1970;
+
+#define DIV(a, b) ((a) / (b) - ((a) % (b) < 0))
+#define LEAPS_THRU_END_OF(y) (DIV (y, 4) - DIV (y, 100) + DIV (y, 400))
+
+ while (days < 0 || days >= (__isleap (y) ? 366 : 365))
+ {
+ /* Guess a corrected year, assuming 365 days per year. */
+ time64_t yg = y + days / 365 - (days % 365 < 0);
+
+ /* Adjust DAYS and Y to match the guessed year. */
+ days -= ((yg - y) * 365
+ + LEAPS_THRU_END_OF (yg - 1)
+ - LEAPS_THRU_END_OF (y - 1));
+ y = yg;
+ }
+ tp->tm_year = y - 1900;
+ if (tp->tm_year != y - 1900)
+ {
+ /* The year cannot be represented due to overflow. */
+ __set_errno (EOVERFLOW);
+ return 0;
+ }
+ tp->tm_yday = days;
+ ip = __mon_yday[__isleap(y)];
+ for (y = 11; days < (long int) ip[y]; --y)
+ continue;
+ days -= ip[y];
+ tp->tm_mon = y;
+ tp->tm_mday = days + 1;
+ return 1;
+}
diff --git a/time/time.h b/time/time.h
index 56fd7ad..2d999ed 100644
--- a/time/time.h
+++ b/time/time.h
@@ -79,6 +79,14 @@ extern time_t time (time_t *__timer) __THROW;
extern double difftime (time_t __time1, time_t __time0)
__THROW __attribute__ ((__const__));
+/* Return the difference between TIME1 and TIME0. */
+extern double difftime64 (time64_t __time1, time64_t __time0)
+ __THROW __attribute__ ((__const__));
+
+#ifdef __USE_TIME_BITS64
+#define difftime difftime64
+#endif
+
/* Return the `time_t' representation of TP and normalize TP. */
extern time_t mktime (struct tm *__tp) __THROW;
@@ -121,9 +129,25 @@ __BEGIN_NAMESPACE_STD
in Universal Coordinated Time (aka Greenwich Mean Time). */
extern struct tm *gmtime (const time_t *__timer) __THROW;
+/* Return the `struct tm' representation of 64-bit-time *TIMER
+ in Universal Coordinated Time (aka Greenwich Mean Time). */
+extern struct tm *gmtime64 (const time64_t *__timer) __THROW;
+
+#ifdef __USE_TIME_BITS64
+#define gmtime gmtime64
+#endif
+
/* Return the `struct tm' representation
of *TIMER in the local timezone. */
extern struct tm *localtime (const time_t *__timer) __THROW;
+
+/* Return the `struct tm' representation
+ of the 64-bit-time *TIMER in the local timezone. */
+extern struct tm *localtime64 (const time64_t *__timer) __THROW;
+
+#ifdef __USE_TIME_BITS64
+#define localtime localtime64
+#endif
__END_NAMESPACE_STD
#ifdef __USE_POSIX
@@ -132,10 +156,29 @@ __END_NAMESPACE_STD
extern struct tm *gmtime_r (const time_t *__restrict __timer,
struct tm *__restrict __tp) __THROW;
+/* Return the `struct tm' representation of 64-bit-time *TIMER
+ in UTC, using *TP to store the result. */
+extern struct tm *gmtime64_r (const time64_t *__restrict __timer,
+ struct tm *__restrict __tp) __THROW;
+
+#ifdef __USE_TIME_BITS64
+#define gmtime_r gmtime64_r
+#endif
+
/* Return the `struct tm' representation of *TIMER in local time,
using *TP to store the result. */
extern struct tm *localtime_r (const time_t *__restrict __timer,
struct tm *__restrict __tp) __THROW;
+
+/* Return the `struct tm' representation of the 64-bit-time *TIMER
+ in local time, using *TP to store the result. */
+extern struct tm *localtime64_r (const time64_t *__restrict __timer,
+ struct tm *__restrict __tp) __THROW;
+
+#ifdef __USE_TIME_BITS64
+#define localtime_r localtime64_r
+#endif
+
#endif /* POSIX */
__BEGIN_NAMESPACE_STD
@@ -145,6 +188,14 @@ extern char *asctime (const struct tm *__tp) __THROW;
/* Equivalent to `asctime (localtime (timer))'. */
extern char *ctime (const time_t *__timer) __THROW;
+
+/* Equivalent to `asctime (localtime64 (timer))'. */
+extern char *ctime64 (const time64_t *__timer) __THROW;
+
+#ifdef __USE_TIME_BITS64
+#define ctime ctime64
+#endif
+
__END_NAMESPACE_STD
#ifdef __USE_POSIX
diff --git a/time/tzfile.c b/time/tzfile.c
index 3fd4569..f4642e7 100644
--- a/time/tzfile.c
+++ b/time/tzfile.c
@@ -637,7 +637,7 @@ __tzfile_default (const char *std, const char *dst,
}
void
-__tzfile_compute (time_t timer, int use_localtime,
+__tzfile_compute (time64_t timer, int use_localtime,
long int *leap_correct, int *leap_hit,
struct tm *tp)
{
@@ -692,7 +692,7 @@ __tzfile_compute (time_t timer, int use_localtime,
/* Convert to broken down structure. If this fails do not
use the string. */
- if (__glibc_unlikely (! __offtime (&timer, 0, tp)))
+ if (__glibc_unlikely (! __offtime64 (&timer, 0, tp)))
goto use_last;
/* Use the rules from the TZ string to compute the change. */
diff --git a/time/tzset.c b/time/tzset.c
index eb42069..3f6b7bf 100644
--- a/time/tzset.c
+++ b/time/tzset.c
@@ -61,7 +61,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;
@@ -451,7 +451,7 @@ tzset_internal (int always, int explicit)
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 = (time64_t) -1;
update_vars ();
return;
}
@@ -550,10 +550,11 @@ compute_change (tz_rule *rule, int year)
/* Figure out the correct timezone for TM and set `__tzname',
- `__timezone', and `__daylight' accordingly. */
+ `__timezone', and `__daylight' accordingly.
+ NOTE: this takes a time64_t value, so passing a time_t value is OK. */
void
internal_function
-__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);
@@ -654,6 +655,61 @@ __tz_convert (const time_t *timer, int use_localtime, struct tm *tp)
}
+/* Return the `struct tm' representation of *TIMER in the local timezone.
+ Use local time if USE_LOCALTIME is nonzero, UTC otherwise. */
+struct tm *
+__tz64_convert (const 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.
+ POSIX.1 8.3.7.2 says that localtime_r is not required to set tzname.
+ This is a good idea since this allows at least a bit more parallelism. */
+ tzset_internal (tp == &_tmbuf && use_localtime, 1);
+
+ if (__use_tzfile)
+ __tzfile_compute (*timer, use_localtime, &leap_correction,
+ &leap_extra_secs, tp);
+ else
+ {
+ if (! __offtime64 (timer, 0, tp))
+ tp = NULL;
+ else
+ __tz_compute (*timer, tp, use_localtime);
+ leap_correction = 0L;
+ leap_extra_secs = 0;
+ }
+
+ __libc_lock_unlock (tzset_lock);
+
+ if (tp)
+ {
+ if (! use_localtime)
+ {
+ tp->tm_isdst = 0;
+ tp->tm_zone = "GMT";
+ tp->tm_gmtoff = 0L;
+ }
+
+ if (__offtime64 (timer, tp->tm_gmtoff - leap_correction, tp))
+ tp->tm_sec += leap_extra_secs;
+ else
+ tp = NULL;
+ }
+
+ return tp;
+}
+
+
libc_freeres_fn (free_mem)
{
while (tzstring_list != NULL)
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=f8a0ab95451a081ce574e3fc80d8a49440b51bc5
commit f8a0ab95451a081ce574e3fc80d8a49440b51bc5
Author: Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
Date: Sun Nov 13 10:40:51 2016 +0100
Support 64-bit syscalls from 32-bit GLIBC clock_gettime and vice versa
diff --git a/sysdeps/unix/sysv/linux/clock_gettime.c b/sysdeps/unix/sysv/linux/clock_gettime.c
index 64eb189..d7da0a4 100644
--- a/sysdeps/unix/sysv/linux/clock_gettime.c
+++ b/sysdeps/unix/sysv/linux/clock_gettime.c
@@ -29,10 +29,23 @@
/* The REALTIME and MONOTONIC clock are definitely supported in the
kernel. */
#define SYSDEP_GETTIME \
- SYSDEP_GETTIME_CPUTIME; \
- case CLOCK_REALTIME: \
- case CLOCK_MONOTONIC: \
- retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp); \
+ SYSDEP_GETTIME_CPUTIME; \
+ case CLOCK_REALTIME: \
+ case CLOCK_MONOTONIC: \
+ retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp); \
+ if (retval == ENOSYS) \
+ { \
+ struct timespec64 tp64; \
+ retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, &tp64); \
+ if (retval >= 0) \
+ { \
+ if (tp64.tv_sec < 0x80000000) \
+ { \
+ tp->tv_sec = (__time_t) tp64.tv_sec; \
+ tp->tv_nsec = (__syscall_slong_t) tp64.tv_nsec; \
+ } \
+ } \
+ } \
break
/* We handled the REALTIME clock here. */
@@ -40,7 +53,20 @@
#define HANDLED_CPUTIME 1
#define SYSDEP_GETTIME_CPU(clock_id, tp) \
- retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp); \
+ retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp); \
+ if (retval == ENOSYS) \
+ { \
+ struct timespec64 tp64; \
+ retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, &tp64); \
+ if (retval >= 0) \
+ { \
+ if (tp64.tv_sec < 0x80000000) \
+ { \
+ tp->tv_sec = (__time_t) tp64.tv_sec; \
+ tp->tv_nsec = (__syscall_slong_t) tp64.tv_nsec; \
+ } \
+ } \
+ } \
break
#define SYSDEP_GETTIME_CPUTIME /* Default catches them too. */
@@ -49,10 +75,21 @@
/* The REALTIME and MONOTONIC clock are definitely supported in the
kernel. */
#define SYSDEP_GETTIME64 \
- SYSDEP_GETTIME64_CPUTIME; \
- case CLOCK_REALTIME: \
- case CLOCK_MONOTONIC: \
- retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp); \
+ SYSDEP_GETTIME64_CPUTIME; \
+ case CLOCK_REALTIME: \
+ case CLOCK_MONOTONIC: \
+ retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp); \
+ if (retval == ENOSYS) \
+ { \
+ struct timespec tp32; \
+ retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, &tp32); \
+ if (retval >= 0) \
+ { \
+ tp->tv_sec = tp32.tv_sec; \
+ if (tp->tv_sec < 0) tp->tv_sec += 0x100000000; \
+ tp->tv_nsec = tp32.tv_nsec; \
+ } \
+ } \
break
/* We handled the REALTIME clock here. */
@@ -60,7 +97,18 @@
#define HANDLED_CPUTIME 1
#define SYSDEP_GETTIME64_CPU(clock_id, tp) \
- retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp); \
+ retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp); \
+ if (retval == ENOSYS) \
+ { \
+ struct timespec tp32; \
+ retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, &tp32); \
+ if (retval >= 0) \
+ { \
+ tp->tv_sec = tp32.tv_sec; \
+ if (tp->tv_sec < 0) tp->tv_sec += 0x100000000; \
+ tp->tv_nsec = tp32.tv_nsec; \
+ } \
+ } \
break
#define SYSDEP_GETTIME64_CPUTIME /* Default catches them too. */
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=e8fe68bbb797f86ec96c637d9647925005ed7328
commit e8fe68bbb797f86ec96c637d9647925005ed7328
Author: Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
Date: Sun Nov 13 10:40:51 2016 +0100
Fix wrong ifdef SYSDEP_GETTIME in __clock_gettime64
diff --git a/sysdeps/unix/clock_gettime.c b/sysdeps/unix/clock_gettime.c
index d967339..30f44c0 100644
--- a/sysdeps/unix/clock_gettime.c
+++ b/sysdeps/unix/clock_gettime.c
@@ -143,7 +143,7 @@ __clock_gettime64 (clockid_t clock_id, struct timespec64 *tp)
switch (clock_id)
{
-#ifdef SYSDEP_GETTIME
+#ifdef SYSDEP_GETTIME64
SYSDEP_GETTIME64;
#endif
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=ccab72f59cb98709fb4d861b36bac7bfec6af98c
commit ccab72f59cb98709fb4d861b36bac7bfec6af98c
Author: Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
Date: Sun Nov 6 18:36:51 2016 +0100
WIP: Y2038: support 64-bit clock_gettime and clock_settime
diff --git a/bits/types.h b/bits/types.h
index 7638bd0..b3dbb2b 100644
--- a/bits/types.h
+++ b/bits/types.h
@@ -145,7 +145,8 @@ __STD_TYPE __CLOCK_T_TYPE __clock_t; /* Type of CPU usage counts. */
__STD_TYPE __RLIM_T_TYPE __rlim_t; /* Type for resource measurement. */
__STD_TYPE __RLIM64_T_TYPE __rlim64_t; /* Type for resource measurement (LFS). */
__STD_TYPE __ID_T_TYPE __id_t; /* General type for IDs. */
-__STD_TYPE __TIME_T_TYPE __time_t; /* Seconds since the Epoch. */
+__STD_TYPE __TIME_T_TYPE __time_t; /* Seconds since the Epoch, Y2038-unsafe. */
+__STD_TYPE __TIME64_T_TYPE __time64_t; /* Seconds since the Epoch, Y2038-safe. */
__STD_TYPE __USECONDS_T_TYPE __useconds_t; /* Count of microseconds. */
__STD_TYPE __SUSECONDS_T_TYPE __suseconds_t; /* Signed count of microseconds. */
@@ -184,6 +185,8 @@ __STD_TYPE __SSIZE_T_TYPE __ssize_t; /* Type of a byte count, or error. */
__STD_TYPE __SYSCALL_SLONG_TYPE __syscall_slong_t;
/* Unsigned long type used in system calls. */
__STD_TYPE __SYSCALL_ULONG_TYPE __syscall_ulong_t;
+/* Signed quad type used in system calls. */
+__STD_TYPE __SYSCALL_SQUAD_TYPE __syscall_squad_t;
/* These few don't really vary by system, they always correspond
to one of the other defined types. */
diff --git a/bits/typesizes.h b/bits/typesizes.h
index d407bf4..d49f40d 100644
--- a/bits/typesizes.h
+++ b/bits/typesizes.h
@@ -48,6 +48,7 @@
#define __ID_T_TYPE __U32_TYPE
#define __CLOCK_T_TYPE __SLONGWORD_TYPE
#define __TIME_T_TYPE __SLONGWORD_TYPE
+#define __TIME64_T_TYPE __SQUAD_TYPE
#define __USECONDS_T_TYPE __U32_TYPE
#define __SUSECONDS_T_TYPE __SLONGWORD_TYPE
#define __DADDR_T_TYPE __S32_TYPE
@@ -59,6 +60,7 @@
#define __SSIZE_T_TYPE __SWORD_TYPE
#define __SYSCALL_SLONG_TYPE __SLONGWORD_TYPE
#define __SYSCALL_ULONG_TYPE __ULONGWORD_TYPE
+#define __SYSCALL_SQUAD_TYPE __SQUAD_TYPE
#define __CPU_MASK_TYPE __ULONGWORD_TYPE
#ifdef __LP64__
diff --git a/include/features.h b/include/features.h
index dc8ae79..cef60ac 100644
--- a/include/features.h
+++ b/include/features.h
@@ -356,6 +356,10 @@
# define __USE_FILE_OFFSET64 1
#endif
+#if defined _TIME_BITS && _TIME_BITS == 64
+# define __USE_TIME_BITS64 1
+#endif
+
#if defined _DEFAULT_SOURCE
# define __USE_MISC 1
#endif
diff --git a/include/time.h b/include/time.h
index 684ceb8..2fa0764 100644
--- a/include/time.h
+++ b/include/time.h
@@ -21,7 +21,10 @@ libc_hidden_proto (strptime)
extern __typeof (clock_getres) __clock_getres;
extern __typeof (clock_gettime) __clock_gettime;
libc_hidden_proto (__clock_gettime)
+extern __typeof (clock_gettime64) __clock_gettime64;
+libc_hidden_proto (__clock_gettime64)
extern __typeof (clock_settime) __clock_settime;
+extern __typeof (clock_settime64) __clock_settime64;
extern __typeof (clock_nanosleep) __clock_nanosleep;
extern __typeof (clock_getcpuclockid) __clock_getcpuclockid;
diff --git a/sysdeps/unix/clock_gettime.c b/sysdeps/unix/clock_gettime.c
index 5262066..d967339 100644
--- a/sysdeps/unix/clock_gettime.c
+++ b/sysdeps/unix/clock_gettime.c
@@ -134,3 +134,51 @@ __clock_gettime (clockid_t clock_id, struct timespec *tp)
}
weak_alias (__clock_gettime, clock_gettime)
libc_hidden_def (__clock_gettime)
+
+/* Get current value of CLOCK and store it in TP, 64-bit version. */
+int
+__clock_gettime64 (clockid_t clock_id, struct timespec64 *tp)
+{
+ int retval = -1;
+
+ switch (clock_id)
+ {
+#ifdef SYSDEP_GETTIME
+ SYSDEP_GETTIME64;
+#endif
+
+#ifndef HANDLED_REALTIME
+ case CLOCK_REALTIME:
+ {
+ struct timeval tv;
+ retval = gettimeofday (&tv, NULL);
+ if (retval == 0)
+ TIMEVAL_TO_TIMESPEC (&tv, tp);
+ }
+ break;
+#endif
+
+ default:
+#ifdef SYSDEP_GETTIME64_CPU
+ SYSDEP_GETTIME64_CPU (clock_id, tp);
+#endif
+#if HP_TIMING_AVAIL
+ if ((clock_id & ((1 << CLOCK_IDFIELD_SIZE) - 1))
+ == CLOCK_THREAD_CPUTIME_ID)
+ retval = hp_timing_gettime (clock_id, tp);
+ else
+#endif
+ __set_errno (EINVAL);
+ break;
+
+#if HP_TIMING_AVAIL && !defined HANDLED_CPUTIME
+ case CLOCK_PROCESS_CPUTIME_ID:
+ retval = hp_timing_gettime (clock_id, tp);
+ break;
+#endif
+ }
+
+ return retval;
+}
+weak_alias (__clock_gettime64, clock_gettime64)
+libc_hidden_def (__clock_gettime64)
diff --git a/sysdeps/unix/clock_settime.c b/sysdeps/unix/clock_settime.c
index 957a4b1..690e799 100644
--- a/sysdeps/unix/clock_settime.c
+++ b/sysdeps/unix/clock_settime.c
@@ -69,8 +69,77 @@ hp_timing_settime (clockid_t clock_id, const struct timespec *tp)
}
#endif
+/*
+ * We define the 64- and 32-bit versions of clock_gettime. The client
+ * code determines which one is called:
+ *
+ * - if client code defines ___USE_TIME_BITS64, then GLIBC defines
+ * _TIME_BITS equal to 64, and the 64-bit version of clock_gettime
+ * gets declared and used.
+ *
+ * - if client code does not define ___USE_TIME_BITS64, then GLIBC does
+ * not define _TIME_BITS and the 32-bit version of clock_gettime gets
+ * declared and used.
+ */
+
+
+/* Set CLOCK to value TP, 64-bit Y2038-safe version. */
+int
+__clock_settime64 (clockid_t clock_id, const struct timespec64 *tp)
+{
+ int retval;
+
+ /* Make sure the time cvalue is OK. */
+ if (tp->tv_nsec < 0 || tp->tv_nsec >= 1000000000)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ switch (clock_id)
+ {
+#define HANDLE_REALTIME \
+ do { \
+ struct timeval tv; \
+ TIMESPEC_TO_TIMEVAL (&tv, tp); \
+ \
+ retval = settimeofday (&tv, NULL); \
+ } while (0)
+
+#ifdef SYSDEP_SETTIME64
+ SYSDEP_SETTIME64;
+#endif
+
+#ifndef HANDLED_REALTIME
+ case CLOCK_REALTIME:
+ HANDLE_REALTIME;
+ break;
+#endif
+
+ default:
+#ifdef SYSDEP_SETTIME64_CPU
+ SYSDEP_SETTIME64_CPU;
+#endif
+#ifndef HANDLED_CPUTIME
+# if HP_TIMING_AVAIL
+ if (CPUCLOCK_WHICH (clock_id) == CLOCK_PROCESS_CPUTIME_ID
+ || CPUCLOCK_WHICH (clock_id) == CLOCK_THREAD_CPUTIME_ID)
+ retval = hp_timing_settime (clock_id, tp);
+ else
+# endif
+ {
+ __set_errno (EINVAL);
+ retval = -1;
+ }
+#endif
+ break;
+ }
+
+ return retval;
+}
+weak_alias (__clock_settime64, clock_settime64)
-/* Set CLOCK to value TP. */
+/* Set CLOCK to value TP, 64-bit Y2038-safe version. */
int
__clock_settime (clockid_t clock_id, const struct timespec *tp)
{
diff --git a/sysdeps/unix/sysv/linux/arm/Versions b/sysdeps/unix/sysv/linux/arm/Versions
index 7e5ba53..7410904 100644
--- a/sysdeps/unix/sysv/linux/arm/Versions
+++ b/sysdeps/unix/sysv/linux/arm/Versions
@@ -9,11 +9,16 @@ libc {
}
GLIBC_2.24 {
recvmsg; sendmsg;
+ clock_gettime64; clock_settime64;
}
GLIBC_PRIVATE {
# A copy of sigaction lives in libpthread, and needs these.
__default_sa_restorer; __default_rt_sa_restorer;
# nptl/pthread_cond_timedwait.c uses INTERNAL_VSYSCALL(clock_gettime).
__vdso_clock_gettime;
+ # (aaribaud) do we need this?
+ __clock_gettime64;
+ __clock_settime64;
+ __vdso_clock_gettime64;
}
}
diff --git a/sysdeps/unix/sysv/linux/arm/init-first.c b/sysdeps/unix/sysv/linux/arm/init-first.c
index 3c289c2..def201e 100644
--- a/sysdeps/unix/sysv/linux/arm/init-first.c
+++ b/sysdeps/unix/sysv/linux/arm/init-first.c
@@ -23,6 +23,7 @@
int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *) attribute_hidden;
int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *);
+int (*VDSO_SYMBOL(clock_gettime64)) (clockid_t, struct timespec64 *);
static inline void
_libc_vdso_platform_setup (void)
@@ -36,6 +37,11 @@ _libc_vdso_platform_setup (void)
p = _dl_vdso_vsym ("__vdso_clock_gettime", &linux26);
PTR_MANGLE (p);
VDSO_SYMBOL (clock_gettime) = p;
+
+ /* (aaribaud) TODO: map to version where clock_gettime64 officially appears */
+ p = _dl_vdso_vsym ("__vdso_clock_gettime64", NULL);
+ PTR_MANGLE (p);
+ VDSO_SYMBOL (clock_gettime64) = p;
}
# define VDSO_SETUP _libc_vdso_platform_setup
diff --git a/sysdeps/unix/sysv/linux/arm/libc-vdso.h b/sysdeps/unix/sysv/linux/arm/libc-vdso.h
index ae37b57..d67a903 100644
--- a/sysdeps/unix/sysv/linux/arm/libc-vdso.h
+++ b/sysdeps/unix/sysv/linux/arm/libc-vdso.h
@@ -27,6 +27,7 @@
extern int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *)
attribute_hidden;
extern int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *);
+extern int (*VDSO_SYMBOL(clock_gettime64)) (clockid_t, struct timespec64 *);
#endif
diff --git a/sysdeps/unix/sysv/linux/arm/libc.abilist b/sysdeps/unix/sysv/linux/arm/libc.abilist
index 66112dd..3df7ef4 100644
--- a/sysdeps/unix/sysv/linux/arm/libc.abilist
+++ b/sysdeps/unix/sysv/linux/arm/libc.abilist
@@ -90,6 +90,8 @@ GLIBC_2.23 fts64_read F
GLIBC_2.23 fts64_set F
GLIBC_2.24 GLIBC_2.24 A
GLIBC_2.24 quick_exit F
+GLIBC_2.24 clock_gettime64 F
+GLIBC_2.24 clock_settime64 F
GLIBC_2.25 GLIBC_2.25 A
GLIBC_2.25 __explicit_bzero_chk F
GLIBC_2.25 explicit_bzero F
diff --git a/sysdeps/unix/sysv/linux/clock_gettime.c b/sysdeps/unix/sysv/linux/clock_gettime.c
index e232f69..64eb189 100644
--- a/sysdeps/unix/sysv/linux/clock_gettime.c
+++ b/sysdeps/unix/sysv/linux/clock_gettime.c
@@ -44,4 +44,24 @@
break
#define SYSDEP_GETTIME_CPUTIME /* Default catches them too. */
+/* 64-bit versions */
+
+/* The REALTIME and MONOTONIC clock are definitely supported in the
+ kernel. */
+#define SYSDEP_GETTIME64 \
+ SYSDEP_GETTIME64_CPUTIME; \
+ case CLOCK_REALTIME: \
+ case CLOCK_MONOTONIC: \
+ retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp); \
+ break
+
+/* We handled the REALTIME clock here. */
+#define HANDLED_REALTIME 1
+#define HANDLED_CPUTIME 1
+
+#define SYSDEP_GETTIME64_CPU(clock_id, tp) \
+ retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp); \
+ break
+#define SYSDEP_GETTIME64_CPUTIME /* Default catches them too. */
+
#include <sysdeps/unix/clock_gettime.c>
diff --git a/sysdeps/unix/sysv/linux/clock_settime.c b/sysdeps/unix/sysv/linux/clock_settime.c
index 058c518..d3c98c0 100644
--- a/sysdeps/unix/sysv/linux/clock_settime.c
+++ b/sysdeps/unix/sysv/linux/clock_settime.c
@@ -23,6 +23,11 @@
/* The REALTIME clock is definitely supported in the kernel. */
+#define SYSDEP_SETTIME64 \
+ case CLOCK_REALTIME: \
+ retval = INLINE_SYSCALL (clock_settime64, 2, clock_id, tp); \
+ break
+
#define SYSDEP_SETTIME \
case CLOCK_REALTIME: \
retval = INLINE_SYSCALL (clock_settime, 2, clock_id, tp); \
@@ -32,6 +37,9 @@
#define HANDLED_REALTIME 1
#define HANDLED_CPUTIME 1
+#define SYSDEP_SETTIME64_CPU \
+ retval = INLINE_SYSCALL (clock_settime64, 2, clock_id, tp)
+
#define SYSDEP_SETTIME_CPU \
retval = INLINE_SYSCALL (clock_settime, 2, clock_id, tp)
diff --git a/time/bits/types/struct_timespec.h b/time/bits/types/struct_timespec.h
index 644db9f..dcb0ab5 100644
--- a/time/bits/types/struct_timespec.h
+++ b/time/bits/types/struct_timespec.h
@@ -11,4 +11,11 @@ struct timespec
__syscall_slong_t tv_nsec; /* Nanoseconds. */
};
+/* This one is for holding a Y2038-safe time value. */
+struct timespec64
+{
+ __time64_t tv_sec; /* Seconds. */
+ __syscall_squad_t tv_nsec; /* Nanoseconds. */
+};
+
#endif
diff --git a/time/time.h b/time/time.h
index 7f98338..56fd7ad 100644
--- a/time/time.h
+++ b/time/time.h
@@ -223,10 +223,19 @@ extern int clock_getres (clockid_t __clock_id, struct timespec *__res) __THROW;
/* Get current value of clock CLOCK_ID and store it in TP. */
extern int clock_gettime (clockid_t __clock_id, struct timespec *__tp) __THROW;
+extern int clock_gettime64 (clockid_t __clock_id, struct timespec64 *__tp) __THROW;
/* Set clock CLOCK_ID to value TP. */
extern int clock_settime (clockid_t __clock_id, const struct timespec *__tp)
__THROW;
+extern int clock_settime64 (clockid_t __clock_id, const struct timespec64 *__tp)
+ __THROW;
+
+#ifdef __USE_TIME_BITS64
+#define timespec timespec64
+#define clock_gettime clock_gettime64
+#define clock_settime clock_settime64
+#endif
# ifdef __USE_XOPEN2K
/* High-resolution sleep with the specified clock.
-----------------------------------------------------------------------
hooks/post-receive
--
GNU C Library master sources