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-2.25 created. glibc-2.25-13-g11d2a1a
- From: aaribaud at sourceware dot org
- To: glibc-cvs at sourceware dot org
- Date: 6 Apr 2017 11:41:50 -0000
- Subject: GNU C Library master sources branch aaribaud/y2038-2.25 created. glibc-2.25-13-g11d2a1a
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-2.25 has been created
at 11d2a1a4ecceb7b9007f074efa75f8f6c0c704bc (commit)
- Log -----------------------------------------------------------------
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=11d2a1a4ecceb7b9007f074efa75f8f6c0c704bc
commit 11d2a1a4ecceb7b9007f074efa75f8f6c0c704bc
Author: Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
Date: Wed Apr 5 22:51:34 2017 +0200
Add __timegm64
diff --git a/sysdeps/unix/sysv/linux/arm/Versions b/sysdeps/unix/sysv/linux/arm/Versions
index 6097a86..8141243 100644
--- a/sysdeps/unix/sysv/linux/arm/Versions
+++ b/sysdeps/unix/sysv/linux/arm/Versions
@@ -29,5 +29,7 @@ libc {
__localtime64; __localtime64_r;
# Y2038-proof mktime and timelocal APIs
__mktime64; __timelocal64_r;
+ # Y2038-proof timegm API
+ __timegm64;
}
}
diff --git a/time/time.h b/time/time.h
index 87edaa6..eb9ab4c 100644
--- a/time/time.h
+++ b/time/time.h
@@ -269,6 +269,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. */
+#ifdef __USE_TIME_BITS64
+# if defined(__REDIRECT)
+extern time_t __REDIRECT (timegm, (struct tm *__tp), __timegm64) __THROW;
+# else
+# define timegm __timegm64
+# endif
+#endif
extern time_t timegm (struct tm *__tp) __THROW;
/* Another name for `mktime'. */
diff --git a/time/timegm.c b/time/timegm.c
index b0f5d16..89fac10 100644
--- a/time/timegm.c
+++ b/time/timegm.c
@@ -36,6 +36,9 @@
time_t __mktime_internal (struct tm *,
struct tm * (*) (time_t const *, struct tm *),
time_t *);
+__time64_t __mktime64_internal (struct tm *,
+ struct tm * (*) (__time64_t const *, struct tm *),
+ __time64_t *);
#endif
time_t
@@ -45,3 +48,11 @@ timegm (struct tm *tmp)
tmp->tm_isdst = 0;
return __mktime_internal (tmp, __gmtime_r, &gmtime_offset);
}
+
+__time64_t
+__timegm64 (struct tm *tmp)
+{
+ static __time64_t gmtime64_offset;
+ tmp->tm_isdst = 0;
+ return __mktime64_internal (tmp, __gmtime64_r, &gmtime64_offset);
+}
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=a3221ada925f9564b838641ff738e5772d6e64a7
commit a3221ada925f9564b838641ff738e5772d6e64a7
Author: Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
Date: Tue Feb 7 22:21:14 2017 +0100
Add __mktime64 and __timelocal64
diff --git a/include/time.h b/include/time.h
index d9ee0d1..10c72ba 100644
--- a/include/time.h
+++ b/include/time.h
@@ -85,6 +85,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 b341f8a..6097a86 100644
--- a/sysdeps/unix/sysv/linux/arm/Versions
+++ b/sysdeps/unix/sysv/linux/arm/Versions
@@ -27,5 +27,7 @@ libc {
__ctime64; __ctime64_r;
__gmtime64; __gmtime64_r;
__localtime64; __localtime64_r;
+ # Y2038-proof mktime and timelocal APIs
+ __mktime64; __timelocal64_r;
}
}
diff --git a/time/mktime.c b/time/mktime.c
index 4c48d35..3bd2631 100644
--- a/time/mktime.c
+++ b/time/mktime.c
@@ -599,6 +599,412 @@ 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);
+}
#if defined DEBUG_MKTIME && DEBUG_MKTIME
diff --git a/time/time.h b/time/time.h
index 33c4b07..87edaa6 100644
--- a/time/time.h
+++ b/time/time.h
@@ -88,9 +88,15 @@ extern double difftime (time_t __time1, time_t __time0)
__THROW __attribute__ ((__const__));
/* Return the `time_t' representation of TP and normalize TP. */
+#ifdef __USE_TIME_BITS64
+# if defined(__REDIRECT)
+extern time_t __REDIRECT (mktime, (struct tm *__tp), __mktime64) __THROW;
+# else
+# define mktime __mktime64
+# endif
+#endif
extern time_t mktime (struct tm *__tp) __THROW;
-
/* Format TP into S according to FORMAT.
Write no more than MAXSIZE characters and return the number
of characters written, or 0 if it would exceed MAXSIZE. */
@@ -266,6 +272,13 @@ extern int stime (const time_t *__when) __THROW;
extern time_t timegm (struct tm *__tp) __THROW;
/* Another name for `mktime'. */
+#ifdef __USE_TIME_BITS64
+# if defined(__REDIRECT)
+extern time_t __REDIRECT (timelocal, (struct tm *__tp), __timelocal64) __THROW;
+# else
+# define timelocal __timelocal64
+# endif
+#endif
extern time_t timelocal (struct tm *__tp) __THROW;
/* Return the number of days in YEAR. */
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=1d18ada2f6fa3b91ae53c47264144fac328181c3
commit 1d18ada2f6fa3b91ae53c47264144fac328181c3
Author: Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
Date: Wed Mar 29 12:01:45 2017 +0200
Add 64-bit 'broken-up time' APIs (see detail in commit msg)
This consists in the following API additions:
([file] 32-bit function -> [file] 64-bit variant)
time/ctime.c ctime() -> __ctime64()
time/ctime_r.c ctime_r() -> __ctime64_r()
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 6b10d74..d9ee0d1 100644
--- a/include/time.h
+++ b/include/time.h
@@ -12,6 +12,8 @@ extern __typeof (strftime_l) __strftime_l;
libc_hidden_proto (__strftime_l)
extern __typeof (strptime_l) __strptime_l;
+extern struct tm *__localtime64 (const __time64_t *__timer);
+
libc_hidden_proto (time)
libc_hidden_proto (asctime)
libc_hidden_proto (mktime)
@@ -67,13 +69,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
@@ -86,15 +88,25 @@ extern time_t __mktime_internal (struct tm *__tp,
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 *__localtime64_r (const __time64_t *__timer,
+ struct tm *__tp) attribute_hidden;
+
+extern struct tm *__gmtime_r (const __time_t *__restrict __timer,
struct tm *__restrict __tp);
libc_hidden_proto (__gmtime_r)
+extern struct tm *__gmtime64_r (const __time64_t *__restrict __timer,
+ struct tm *__restrict __tp);
+
/* 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 (const __time_t *__timer,
+ long int __offset,
+ struct tm *__tp);
+
+extern int __offtime64 (const __time64_t *__timer,
long int __offset,
struct tm *__tp);
@@ -102,7 +114,9 @@ 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);
+
+extern struct tm *__tz_convert64 (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. */
diff --git a/sysdeps/unix/sysv/linux/arm/Versions b/sysdeps/unix/sysv/linux/arm/Versions
index ae4d7b1..b341f8a 100644
--- a/sysdeps/unix/sysv/linux/arm/Versions
+++ b/sysdeps/unix/sysv/linux/arm/Versions
@@ -23,5 +23,9 @@ libc {
__vdso_clock_gettime64;
# Y2038-proof difftime is actually __difftime64
__difftime64;
+ # Y2038-proof 'broken-up time' APIs
+ __ctime64; __ctime64_r;
+ __gmtime64; __gmtime64_r;
+ __localtime64; __localtime64_r;
}
}
diff --git a/time/ctime.c b/time/ctime.c
index 7baca1b..a5150c1 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/ctime_r.c b/time/ctime_r.c
index ecd7731..74d856f 100644
--- a/time/ctime_r.c
+++ b/time/ctime_r.c
@@ -27,3 +27,12 @@ ctime_r (const time_t *t, char *buf)
struct tm tm;
return __asctime_r (__localtime_r (t, &tm), buf);
}
+
+/* Return a string as returned by asctime which is the representation
+ of *T in that form. Reentrant Y2038-proof version. */
+char *
+__ctime64_r (const __time64_t *t, char *buf)
+{
+ struct tm tm;
+ return __asctime_r (__localtime64_r (t, &tm), buf);
+}
diff --git a/time/gmtime.c b/time/gmtime.c
index 049d551..7662c1d 100644
--- a/time/gmtime.c
+++ b/time/gmtime.c
@@ -35,3 +35,18 @@ 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 __tz_convert64 (t, 0, tp);
+}
+
+/* Return the `struct tm' representation of 64-bit-time *T in UTC. */
+struct tm *
+__gmtime64 (const __time64_t *t)
+{
+ return __tz_convert64 (t, 0, &_tmbuf);
+}
diff --git a/time/localtime.c b/time/localtime.c
index 07dd67c..fd2d997 100644
--- a/time/localtime.c
+++ b/time/localtime.c
@@ -39,3 +39,20 @@ 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 __tz_convert64 (t, 1, tp);
+}
+
+/* Return the `struct tm' representation of *T in local time. */
+struct tm *
+__localtime64 (const __time64_t *t)
+{
+ return __tz_convert64 (t, 1, &_tmbuf);
+}
diff --git a/time/offtime.c b/time/offtime.c
index 75a28fe..84237db 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 dd8795e..33c4b07 100644
--- a/time/time.h
+++ b/time/time.h
@@ -125,37 +125,84 @@ 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). */
+#ifdef __USE_TIME_BITS64
+# if defined(__REDIRECT)
+extern struct tm * __REDIRECT (gmtime, (const time_t *__timer),
+ __gmtime64) __THROW;
+# else
+# define gmtime __gmtime64
+# endif
+#endif
extern struct tm *gmtime (const time_t *__timer) __THROW;
/* Return the `struct tm' representation
of *TIMER in the local timezone. */
+#ifdef __USE_TIME_BITS64
+# if defined(__REDIRECT)
+extern struct tm * __REDIRECT (localtime, (const time_t *__timer),
+ __localtime64) __THROW;
+# else
+# define localtime __localtime64
+# endif
+#endif
extern struct tm *localtime (const time_t *__timer) __THROW;
+
__END_NAMESPACE_STD
#ifdef __USE_POSIX
+
/* Return the `struct tm' representation of *TIMER in UTC,
using *TP to store the result. */
+#ifdef __USE_TIME_BITS64
+# if defined(__REDIRECT)
+extern struct tm * __REDIRECT (gmtime_r, (const time_t *__restrict
+ __timer, struct tm *__restrict __tp), __gmtime64_r) __THROW;
+# else
+# define gmtime_r __gmtime64_r
+# endif
+#endif
extern struct tm *gmtime_r (const time_t *__restrict __timer,
struct tm *__restrict __tp) __THROW;
/* Return the `struct tm' representation of *TIMER in local time,
using *TP to store the result. */
+#ifdef __USE_TIME_BITS64
+# if defined(__REDIRECT)
+extern struct tm * __REDIRECT (localtime_r, (const time_t *__restrict
+ __timer, struct tm *__restrict __tp), __localtime64_r) __THROW;
+# else
+# define localtime_r __localtime64_r
+# endif
+#endif
extern struct tm *localtime_r (const time_t *__restrict __timer,
struct tm *__restrict __tp) __THROW;
+
#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))'. */
+#ifdef __USE_TIME_BITS64
+# if defined(__REDIRECT)
+extern char * __REDIRECT (ctime, (const time_t *__timer),
+ __ctime64) __THROW;
+# else
+# define ctime __ctime64
+# endif
+#endif
extern char *ctime (const time_t *__timer) __THROW;
+
__END_NAMESPACE_STD
#ifdef __USE_POSIX
+
/* Reentrant versions of the above functions. */
/* Return in BUF a string of the form "Day Mon dd hh:mm:ss yyyy\n"
@@ -164,8 +211,17 @@ extern char *asctime_r (const struct tm *__restrict __tp,
char *__restrict __buf) __THROW;
/* Equivalent to `asctime_r (localtime_r (timer, *TMP*), buf)'. */
+#ifdef __USE_TIME_BITS64
+# if defined(__REDIRECT)
+extern char * __REDIRECT (ctime_r, (const time_t *__restrict __timer,
+ char *__restrict __buf), __ctime64_r) __THROW;
+# else
+# define ctime_r __ctime64_r
+# endif
+#endif
extern char *ctime_r (const time_t *__restrict __timer,
char *__restrict __buf) __THROW;
+
#endif /* POSIX */
diff --git a/time/tzfile.c b/time/tzfile.c
index 3fd4569..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 (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..cd9df8f 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 *
+__tz_convert64 (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=821f9fe279b6713358897ae30f3671a314d32efa
commit 821f9fe279b6713358897ae30f3671a314d32efa
Author: Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
Date: Wed Mar 29 11:57:53 2017 +0200
Add __difftime64
diff --git a/sysdeps/unix/sysv/linux/arm/Versions b/sysdeps/unix/sysv/linux/arm/Versions
index cfe1f15..ae4d7b1 100644
--- a/sysdeps/unix/sysv/linux/arm/Versions
+++ b/sysdeps/unix/sysv/linux/arm/Versions
@@ -21,5 +21,7 @@ libc {
__clock_gettime64; __clock_settime64; __clock_getres64;
# Y2038 clock_gettime/__clock_gettime64 use INTERNAL_VSYSCALL(clock_gettime64).
__vdso_clock_gettime64;
+ # Y2038-proof difftime is actually __difftime64
+ __difftime64;
}
}
diff --git a/time/difftime.c b/time/difftime.c
index e5e3311..1b2494c 100644
--- a/time/difftime.c
+++ b/time/difftime.c
@@ -119,3 +119,12 @@ __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);
+}
diff --git a/time/time.h b/time/time.h
index 42fe443..dd8795e 100644
--- a/time/time.h
+++ b/time/time.h
@@ -76,6 +76,14 @@ extern clock_t clock (void) __THROW;
extern time_t time (time_t *__timer) __THROW;
/* Return the difference between TIME1 and TIME0. */
+#ifdef __USE_TIME_BITS64
+# if defined(__REDIRECT)
+extern double __REDIRECT (difftime, (time_t __time1, time_t __time0),
+ __difftime64) __THROW;
+# else
+# define difftime __difftime64
+# endif
+#endif
extern double difftime (time_t __time1, time_t __time0)
__THROW __attribute__ ((__const__));
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=e38285ad22a38e59020b424a0dd959c8ea0229be
commit e38285ad22a38e59020b424a0dd959c8ea0229be
Author: Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
Date: Wed Mar 29 07:50:34 2017 +0200
Add __clock_gettime64, __clock_settime64, and __clock_getres64
diff --git a/bits/types.h b/bits/types.h
index f5b2d42..1d3f83f 100644
--- a/bits/types.h
+++ b/bits/types.h
@@ -185,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;
+/* Unsigned long 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 a916cc1..d49f40d 100644
--- a/bits/typesizes.h
+++ b/bits/typesizes.h
@@ -60,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/time.h b/include/time.h
index 684ceb8..6b10d74 100644
--- a/include/time.h
+++ b/include/time.h
@@ -4,6 +4,8 @@
#ifndef _ISOMAC
# include <xlocale.h>
+#include <endian.h>
+
__BEGIN_DECLS
extern __typeof (strftime_l) __strftime_l;
@@ -18,10 +20,30 @@ libc_hidden_proto (localtime)
libc_hidden_proto (strftime)
libc_hidden_proto (strptime)
+/* Used by __clock_gettime64, __clock_settime64, __clock_getres64. */
+#if BYTE_ORDER == BIG_ENDIAN
+struct __timespec64
+{
+ __time64_t tv_sec; /* Seconds */
+ int tv_pad: 32; /* Padding named for checking/setting */
+ __syscall_slong_t tv_nsec; /* Nanoseconds */
+};
+#else
+struct __timespec64
+{
+ __time64_t tv_sec; /* Seconds */
+ __syscall_slong_t tv_nsec; /* Nanoseconds */
+ int tv_pad: 32; /* Padding named for checking/setting */
+};
+#endif
+
extern __typeof (clock_getres) __clock_getres;
extern __typeof (clock_gettime) __clock_gettime;
+extern int __clock_getres64 (clockid_t __clock_id, struct __timespec64 *__res) __THROW;
libc_hidden_proto (__clock_gettime)
+extern int __clock_gettime64 (clockid_t __clock_id, struct __timespec64 *__tp) __THROW;
extern __typeof (clock_settime) __clock_settime;
+extern int __clock_settime64 (clockid_t __clock_id, const struct __timespec64 *__tp) __THROW;
extern __typeof (clock_nanosleep) __clock_nanosleep;
extern __typeof (clock_getcpuclockid) __clock_getcpuclockid;
diff --git a/sysdeps/posix/clock_getres.c b/sysdeps/posix/clock_getres.c
index b6248be..07ff748 100644
--- a/sysdeps/posix/clock_getres.c
+++ b/sysdeps/posix/clock_getres.c
@@ -22,7 +22,7 @@
#include <unistd.h>
#include <sys/param.h>
#include <libc-internal.h>
-
+#include <kernel_timespec.h>
#if HP_TIMING_AVAIL
static long int nsec; /* Clock frequency of the processor. */
@@ -53,6 +53,33 @@ hp_timing_getres (struct timespec *res)
return 0;
}
+
+static int
+hp_timing_getres64 (struct __timespec64 *res)
+{
+ if (__glibc_unlikely (nsec == 0))
+ {
+ hp_timing_t freq;
+
+ /* This can only happen if we haven't initialized the `nsec'
+ variable yet. Do this now. We don't have to protect this
+ code against multiple execution since all of them should
+ lead to the same result. */
+ freq = __get_clockfreq ();
+ if (__glibc_unlikely (freq == 0))
+ /* Something went wrong. */
+ return -1;
+
+ nsec = MAX (UINT64_C (1000000000) / freq, 1);
+ }
+
+ /* Fill in the values.
+ The seconds are always zero (unless we have a 1Hz machine). */
+ res->tv_sec = 0;
+ res->tv_nsec = nsec;
+
+ return 0;
+}
#endif
static inline int
@@ -73,6 +100,24 @@ realtime_getres (struct timespec *res)
return -1;
}
+static inline int
+realtime_getres64 (struct __timespec64 *res)
+{
+ long int clk_tck = sysconf (_SC_CLK_TCK);
+
+ if (__glibc_likely (clk_tck != -1))
+ {
+ /* This implementation assumes that the realtime clock has a
+ resolution higher than 1 second. This is the case for any
+ reasonable implementation. */
+ res->tv_sec = 0;
+ res->tv_nsec = 1000000000 / clk_tck;
+ return 0;
+ }
+
+ return -1;
+}
+
/* Get resolution of clock. */
int
@@ -116,3 +161,44 @@ __clock_getres (clockid_t clock_id, struct timespec *res)
return retval;
}
weak_alias (__clock_getres, clock_getres)
+
+int
+__clock_getres64 (clockid_t clock_id, struct __timespec64 *res)
+{
+ int retval = -1;
+
+ switch (clock_id)
+ {
+#ifdef SYSDEP_GETRES64
+ SYSDEP_GETRES64;
+#endif
+
+#ifndef HANDLED_REALTIME64
+ case CLOCK_REALTIME64:
+ retval = realtime_getres64 (res);
+ break;
+#endif /* handled REALTIME */
+
+ default:
+#ifdef SYSDEP_GETRES_CPU64
+ SYSDEP_GETRES_CPU64;
+#endif
+#if HP_TIMING_AVAIL
+ if ((clock_id & ((1 << CLOCK_IDFIELD_SIZE) - 1))
+ == CLOCK_THREAD_CPUTIME_ID)
+ retval = hp_timing_getres64 (res);
+ else
+#endif
+ __set_errno (EINVAL);
+ break;
+
+#if HP_TIMING_AVAIL && !defined HANDLED_CPUTIME
+ case CLOCK_PROCESS_CPUTIME_ID:
+ case CLOCK_THREAD_CPUTIME_ID:
+ retval = hp_timing_getres64 (res);
+ break;
+#endif
+ }
+
+ return retval;
+}
diff --git a/sysdeps/unix/clock_gettime.c b/sysdeps/unix/clock_gettime.c
index 5262066..ac224c9 100644
--- a/sysdeps/unix/clock_gettime.c
+++ b/sysdeps/unix/clock_gettime.c
@@ -134,3 +134,49 @@ __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_GETTIME64
+ 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;
+}
diff --git a/sysdeps/unix/clock_settime.c b/sysdeps/unix/clock_settime.c
index 957a4b1..acdc7a9 100644
--- a/sysdeps/unix/clock_settime.c
+++ b/sysdeps/unix/clock_settime.c
@@ -69,8 +69,76 @@ 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;
+}
-/* Set CLOCK to value TP. */
+/* Set CLOCK to value TP, 64-bit Y2038-unsafe 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..cfe1f15 100644
--- a/sysdeps/unix/sysv/linux/arm/Versions
+++ b/sysdeps/unix/sysv/linux/arm/Versions
@@ -15,5 +15,11 @@ libc {
__default_sa_restorer; __default_rt_sa_restorer;
# nptl/pthread_cond_timedwait.c uses INTERNAL_VSYSCALL(clock_gettime).
__vdso_clock_gettime;
+ # Y2038-proof clock_gettime is actually __clock_gettime64
+ # Y2038-proof clock_settime is actually __clock_settime64
+ # TODO: move to the actual version where the symbol is introduced?
+ __clock_gettime64; __clock_settime64; __clock_getres64;
+ # Y2038 clock_gettime/__clock_gettime64 use INTERNAL_VSYSCALL(clock_gettime64).
+ __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..e4b37af 100644
--- a/sysdeps/unix/sysv/linux/arm/init-first.c
+++ b/sysdeps/unix/sysv/linux/arm/init-first.c
@@ -18,11 +18,13 @@
<http://www.gnu.org/licenses/>. */
#ifdef SHARED
+# include <kernel_timespec.h>
# include <dl-vdso.h>
# include <libc-vdso.h>
int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *) attribute_hidden;
-int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *);
+int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct kernel_timespec32 *);
+long (*VDSO_SYMBOL(clock_gettime64)) (clockid_t, struct kernel_timespec64 *);
static inline void
_libc_vdso_platform_setup (void)
@@ -36,6 +38,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..e7b2e98 100644
--- a/sysdeps/unix/sysv/linux/arm/libc-vdso.h
+++ b/sysdeps/unix/sysv/linux/arm/libc-vdso.h
@@ -26,7 +26,8 @@
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_gettime)) (clockid_t, struct kernel_timespec32 *);
+extern long (*VDSO_SYMBOL(clock_gettime64)) (clockid_t, struct kernel_timespec64 *);
#endif
diff --git a/sysdeps/unix/sysv/linux/clock_getres.c b/sysdeps/unix/sysv/linux/clock_getres.c
index 2b7bb65..966b411 100644
--- a/sysdeps/unix/sysv/linux/clock_getres.c
+++ b/sysdeps/unix/sysv/linux/clock_getres.c
@@ -27,7 +27,26 @@
#include <sysdep-vdso.h>
#define SYSCALL_GETRES \
- retval = INLINE_VSYSCALL (clock_getres, 2, clock_id, res); \
+ retval = INLINE_VSYSCALL (clock_getres64, 2, clock_id, &ts64); \
+ if (retval==0) \
+ { \
+ if (ts64.tv_sec > LONG_MAX) \
+ retval = EOVERFLOW; \
+ else \
+ { \
+ res->tv_sec = ts64.tv_sec; \
+ res->tv_nsec = ts64.tv_nsec; \
+ } \
+ } \
+ else \
+ { \
+ retval = INLINE_VSYSCALL (clock_getres, 2, clock_id, &ts32); \
+ if (retval==0) \
+ { \
+ res->tv_sec = ts32.tv_sec; \
+ res->tv_nsec = ts32.tv_nsec; \
+ } \
+ } \
break
/* The REALTIME and MONOTONIC clock are definitely supported in the
@@ -46,6 +65,48 @@
#define HANDLED_CPUTIME 1
#define SYSDEP_GETRES_CPU SYSCALL_GETRES
-#define SYSDEP_GETRES_CPUTIME /* Default catches them too. */
+#define SYSDEP_GETRES_CPUTIME \
+ struct kernel_timespec64 ts64; \
+ struct kernel_timespec32 ts32; \
+
+/* The 64-bit version */
+
+#define SYSCALL_GETRES64 \
+ retval = INLINE_VSYSCALL (clock_getres64, 2, clock_id, &ts64); \
+ if (retval==0) \
+ { \
+ res->tv_sec = ts64.tv_sec; \
+ res->tv_nsec = ts64.tv_nsec; \
+ } \
+ else \
+ { \
+ retval = INLINE_VSYSCALL (clock_getres, 2, clock_id, &ts32); \
+ if (retval==0) \
+ { \
+ res->tv_sec = ts32.tv_sec; \
+ res->tv_nsec = ts32.tv_nsec; \
+ } \
+ } \
+ break
+
+/* The REALTIME and MONOTONIC clock are definitely supported in the
+ kernel. */
+#define SYSDEP_GETRES64 \
+ SYSDEP_GETRES_CPUTIME64 \
+ case CLOCK_REALTIME: \
+ case CLOCK_MONOTONIC: \
+ case CLOCK_MONOTONIC_RAW: \
+ case CLOCK_REALTIME_COARSE: \
+ case CLOCK_MONOTONIC_COARSE: \
+ SYSCALL_GETRES64
+
+/* We handled the REALTIME clock here. */
+#define HANDLED_REALTIME64 1
+#define HANDLED_CPUTIME64 1
+
+#define SYSDEP_GETRES_CPU64 SYSCALL_GETRES64
+#define SYSDEP_GETRES_CPUTIME64 \
+ struct kernel_timespec64 ts64; \
+ struct kernel_timespec32 ts32; \
#include <sysdeps/posix/clock_getres.c>
diff --git a/sysdeps/unix/sysv/linux/clock_gettime.c b/sysdeps/unix/sysv/linux/clock_gettime.c
index e232f69..6dc7d13 100644
--- a/sysdeps/unix/sysv/linux/clock_gettime.c
+++ b/sysdeps/unix/sysv/linux/clock_gettime.c
@@ -24,6 +24,7 @@
#ifdef HAVE_CLOCK_GETTIME_VSYSCALL
# define HAVE_VSYSCALL
#endif
+#include <kernel_timespec.h>
#include <sysdep-vdso.h>
/* The REALTIME and MONOTONIC clock are definitely supported in the
@@ -32,7 +33,26 @@
SYSDEP_GETTIME_CPUTIME; \
case CLOCK_REALTIME: \
case CLOCK_MONOTONIC: \
- retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp); \
+ retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, &ts64); \
+ if (retval==0) \
+ { \
+ if (ts64.tv_sec > LONG_MAX) \
+ retval = EOVERFLOW; \
+ else \
+ { \
+ tp->tv_sec = ts64.tv_sec; \
+ tp->tv_nsec = ts64.tv_nsec; \
+ } \
+ } \
+ else \
+ { \
+ retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, &ts32); \
+ if (retval==0) \
+ { \
+ tp->tv_sec = ts32.tv_sec; \
+ tp->tv_nsec = ts32.tv_nsec; \
+ } \
+ } \
break
/* We handled the REALTIME clock here. */
@@ -40,8 +60,89 @@
#define HANDLED_CPUTIME 1
#define SYSDEP_GETTIME_CPU(clock_id, tp) \
- retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp); \
+ retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, &ts64); \
+ if (retval==0) \
+ { \
+ if (ts64.tv_sec > LONG_MAX) \
+ retval = EOVERFLOW; \
+ else \
+ { \
+ tp->tv_sec = ts64.tv_sec; \
+ tp->tv_nsec = ts64.tv_nsec; \
+ } \
+ } \
+ else \
+ { \
+ retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, &ts32); \
+ if (retval==0) \
+ { \
+ tp->tv_sec = ts32.tv_sec; \
+ tp->tv_nsec = ts32.tv_nsec; \
+ } \
+ } \
break
-#define SYSDEP_GETTIME_CPUTIME /* Default catches them too. */
+#define SYSDEP_GETTIME_CPUTIME \
+ struct kernel_timespec64 ts64; \
+ struct kernel_timespec32 ts32; \
+
+/* 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, &ts64); \
+ if (retval==0) \
+ { \
+ if (ts64.tv_sec > LONG_MAX) \
+ retval = EOVERFLOW; \
+ else \
+ { \
+ tp->tv_sec = ts64.tv_sec; \
+ tp->tv_nsec = ts64.tv_nsec; \
+ } \
+ } \
+ else \
+ { \
+ retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, &ts32); \
+ if (retval==0) \
+ { \
+ tp->tv_sec = ts32.tv_sec; \
+ tp->tv_nsec = ts32.tv_nsec; \
+ } \
+ } \
+ 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, &ts64); \
+ if (retval==0) \
+ { \
+ if (ts64.tv_sec > LONG_MAX) \
+ retval = EOVERFLOW; \
+ else \
+ { \
+ tp->tv_sec = ts64.tv_sec; \
+ tp->tv_nsec = ts64.tv_nsec; \
+ } \
+ } \
+ else \
+ { \
+ retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, &ts32); \
+ if (retval==0) \
+ { \
+ tp->tv_sec = ts32.tv_sec; \
+ tp->tv_nsec = ts32.tv_nsec; \
+ } \
+ } \
+ break
+#define SYSDEP_GETTIME64_CPUTIME \
+ struct kernel_timespec64 ts64; \
+ struct kernel_timespec32 ts32; \
#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..5cd3b15 100644
--- a/sysdeps/unix/sysv/linux/clock_settime.c
+++ b/sysdeps/unix/sysv/linux/clock_settime.c
@@ -18,11 +18,34 @@
#include <errno.h>
#include <sysdep.h>
#include <time.h>
+#include <kernel_timespec.h>
#include "kernel-posix-cpu-timers.h"
/* The REALTIME clock is definitely supported in the kernel. */
+#define SYSDEP_SETTIME64 \
+ case CLOCK_REALTIME: \
+ { \
+ struct kernel_timespec64 ts64; \
+ ts64.tv_sec = tp->tv_sec; \
+ ts64.tv_nsec = tp->tv_nsec; \
+ retval = INLINE_SYSCALL (clock_settime64, 2, clock_id, &ts64); \
+ if (retval == ENOSYS) { \
+ if (tp->tv_sec > LONG_MAX) { \
+ retval = EOVERFLOW; \
+ } \
+ else \
+ { \
+ struct kernel_timespec32 ts32; \
+ ts32.tv_sec = tp->tv_sec; \
+ ts32.tv_nsec = tp->tv_nsec; \
+ retval = INLINE_SYSCALL (clock_settime, 2, clock_id, &ts32); \
+ } \
+ } \
+ } \
+ break
+
#define SYSDEP_SETTIME \
case CLOCK_REALTIME: \
retval = INLINE_SYSCALL (clock_settime, 2, clock_id, tp); \
@@ -32,6 +55,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/sysdeps/unix/sysv/linux/gettimeofday.c b/sysdeps/unix/sysv/linux/gettimeofday.c
index 6afa407..0f2e1bf 100644
--- a/sysdeps/unix/sysv/linux/gettimeofday.c
+++ b/sysdeps/unix/sysv/linux/gettimeofday.c
@@ -24,6 +24,7 @@
#ifdef HAVE_GETTIMEOFDAY_VSYSCALL
# define HAVE_VSYSCALL
#endif
+#include <kernel_timespec.h>
#include <sysdep-vdso.h>
/* Get the current time of day and timezone information,
diff --git a/sysdeps/unix/sysv/linux/kernel_timespec.h b/sysdeps/unix/sysv/linux/kernel_timespec.h
new file mode 100644
index 0000000..a925d93
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/kernel_timespec.h
@@ -0,0 +1,15 @@
+/* Definition of `struct timespec' used in the kernel, 32- and 64-bit variants. */
+
+#include <bits/types.h>
+
+struct kernel_timespec32
+ {
+ __time_t tv_sec;
+ __syscall_slong_t tv_nsec;
+ };
+
+struct kernel_timespec64
+ {
+ __time64_t tv_sec;
+ __syscall_squad_t tv_nsec;
+ };
diff --git a/sysdeps/unix/sysv/linux/timespec_get.c b/sysdeps/unix/sysv/linux/timespec_get.c
index 1f63e57..17644fe 100644
--- a/sysdeps/unix/sysv/linux/timespec_get.c
+++ b/sysdeps/unix/sysv/linux/timespec_get.c
@@ -22,20 +22,40 @@
#ifdef HAVE_CLOCK_GETTIME_VSYSCALL
# define HAVE_VSYSCALL
#endif
+#include <kernel_timespec.h>
#include <sysdep-vdso.h>
+struct kernel_timespec32 ts32 = { 1, 2 };
+
/* Set TS to calendar time based in time base BASE. */
int
timespec_get (struct timespec *ts, int base)
{
switch (base)
{
+ struct kernel_timespec64 ts64;
+ struct kernel_timespec32 ts32;
int res;
INTERNAL_SYSCALL_DECL (err);
case TIME_UTC:
- res = INTERNAL_VSYSCALL (clock_gettime, err, 2, CLOCK_REALTIME, ts);
- if (INTERNAL_SYSCALL_ERROR_P (res, err))
- return 0;
+ res = INTERNAL_VSYSCALL (clock_gettime64, err, 2, CLOCK_REALTIME, &ts64);
+ if (res == ENOSYS)
+ {
+ res = INTERNAL_VSYSCALL (clock_gettime, err, 2, CLOCK_REALTIME, &ts32);
+ if (INTERNAL_SYSCALL_ERROR_P (res, err))
+ return 0;
+ ts->tv_sec = ts32.tv_sec;
+ ts->tv_nsec = ts32.tv_nsec;
+ }
+ else
+ {
+ if (INTERNAL_SYSCALL_ERROR_P (res, err))
+ return 0;
+ if (ts64.tv_sec > LONG_MAX)
+ return 0;
+ ts->tv_sec = ts64.tv_sec;
+ ts->tv_nsec = ts64.tv_nsec;
+ }
break;
default:
diff --git a/time/bits/types/struct_timespec.h b/time/bits/types/struct_timespec.h
index 644db9f..9a2658d 100644
--- a/time/bits/types/struct_timespec.h
+++ b/time/bits/types/struct_timespec.h
@@ -2,13 +2,33 @@
#define __timespec_defined 1
#include <bits/types.h>
+#include <endian.h>
/* POSIX.1b structure for a time value. This is like a `struct timeval' but
has nanoseconds instead of microseconds. */
+#ifndef __USE_TIME_BITS64
struct timespec
{
__time_t tv_sec; /* Seconds. */
__syscall_slong_t tv_nsec; /* Nanoseconds. */
};
+#else
+/* 64-bit time -- we must pad the 32-bit Posix-mandated long tv_nsec to 64 bit */
+# if BYTE_ORDER == BIG_ENDIAN
+struct timespec
+{
+ __time64_t tv_sec; /* Seconds. */
+ int: 32;
+ __syscall_slong_t tv_nsec; /* Nanoseconds. */
+};
+# else
+struct timespec
+{
+ __time64_t tv_sec; /* Seconds. */
+ __syscall_slong_t tv_nsec; /* Nanoseconds. */
+ int: 32;
+};
+# endif
+#endif
#endif
diff --git a/time/time.h b/time/time.h
index 7f98338..42fe443 100644
--- a/time/time.h
+++ b/time/time.h
@@ -219,12 +219,36 @@ extern int nanosleep (const struct timespec *__requested_time,
/* Get resolution of clock CLOCK_ID. */
+#ifdef __USE_TIME_BITS64
+# if defined(__REDIRECT)
+extern int __REDIRECT (clock_getres, (clockid_t __clock_id, struct
+ timespec *__res), __clock_getres64) __THROW;
+# else
+# define clock_getres __clock_getres64
+# endif
+#endif
extern int clock_getres (clockid_t __clock_id, struct timespec *__res) __THROW;
/* Get current value of clock CLOCK_ID and store it in TP. */
+#ifdef __USE_TIME_BITS64
+# if defined(__REDIRECT)
+extern int __REDIRECT (clock_gettime, (clockid_t __clock_id, struct
+ timespec *__tp), __clock_gettime64) __THROW;
+# else
+# define clock_gettime __clock_gettime64
+# endif
+#endif
extern int clock_gettime (clockid_t __clock_id, struct timespec *__tp) __THROW;
/* Set clock CLOCK_ID to value TP. */
+#ifdef __USE_TIME_BITS64
+# if defined(__REDIRECT)
+extern int __REDIRECT (clock_settime, (clockid_t __clock_id, const struct
+ timespec *__tp), __clock_settime64) __THROW;
+# else
+# define clock_settime __clock_settime64
+# endif
+#endif
extern int clock_settime (clockid_t __clock_id, const struct timespec *__tp)
__THROW;
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=148895744426a1d6f7f04e4bfea9854311a09417
commit 148895744426a1d6f7f04e4bfea9854311a09417
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 wide depending on __USE_TIME_BITS64
This allows the same user source code to be built for 32-bit time
(default case) or for 64-bit time (when _USE_TIME_BITS64 is defined)
without any modification.
diff --git a/bits/types.h b/bits/types.h
index 7638bd0..f5b2d42 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. */
diff --git a/bits/typesizes.h b/bits/typesizes.h
index d407bf4..a916cc1 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
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/time/bits/types/time_t.h b/time/bits/types/time_t.h
index 16e5269..47ad649 100644
--- a/time/bits/types/time_t.h
+++ b/time/bits/types/time_t.h
@@ -5,7 +5,11 @@
__BEGIN_NAMESPACE_STD
/* Returned by `time'. */
+#ifdef __USE_TIME_BITS64
+typedef __time64_t time_t;
+#else
typedef __time_t time_t;
+#endif
__END_NAMESPACE_STD
#ifdef __USE_POSIX
__USING_NAMESPACE_STD(time_t)
-----------------------------------------------------------------------
hooks/post-receive
--
GNU C Library master sources