[RFC,02/52] Y2038: add function __difftime64

Message ID 20170907224219.12483-3-albert.aribaud@3adev.fr
State New
Headers show
Series
  • Make GLIBC Y2038-proof
Related show

Commit Message

Albert ARIBAUD Sept. 7, 2017, 10:41 p.m.
Note: the implementation expects __time64_t arguments but returns
a double like its 32-bit-time counterpart, in order to remain as
source-code-compatible as possible, even though the precision of a
double is only about 55 bits.

The implementation is simpler than its 32-bit counterpart, as it
assumes that all __time64_t implementations are just 64-bit integers.

Also, the implementation does not require a Y2038-proof kernel.

Signed-off-by: Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
---
 sysdeps/unix/sysv/linux/arm/Versions | 7 +++++++
 time/difftime.c                      | 9 +++++++++
 2 files changed, 16 insertions(+)

Patch

diff --git a/sysdeps/unix/sysv/linux/arm/Versions b/sysdeps/unix/sysv/linux/arm/Versions
index 7e5ba53455..d3655768c8 100644
--- a/sysdeps/unix/sysv/linux/arm/Versions
+++ b/sysdeps/unix/sysv/linux/arm/Versions
@@ -16,4 +16,11 @@  libc {
     # nptl/pthread_cond_timedwait.c uses INTERNAL_VSYSCALL(clock_gettime).
     __vdso_clock_gettime;
   }
+
+  # Y2038 symbols are given their own version until they can be put in
+  # the right place
+
+  GLIBC_Y2038 {
+    __difftime64;
+  }
 }
diff --git a/time/difftime.c b/time/difftime.c
index e5e3311744..1b2494c727 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);
+}