summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>2017-03-29 11:57:53 +0200
committerAlbert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>2017-06-28 07:29:04 +0200
commitc105c7d64bec61acc38a8f2dbabc657f12319e34 (patch)
tree50ac73071eff9e934111e5aa745cf54cd7ffc1f6
parent419246d155840ce465210febf0a5109667fe55e8 (diff)
downloadglibc-c105c7d64bec61acc38a8f2dbabc657f12319e34.tar.gz
Y2038: implement Y2038-proof difftime
With -D_TIME_BITS=64, the 'difftime' API is implemented by function '__difftime64'. The API 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 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.
-rw-r--r--sysdeps/unix/sysv/linux/arm/Versions7
-rw-r--r--time/difftime.c9
-rw-r--r--time/time.h8
3 files changed, 24 insertions, 0 deletions
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);
+}
diff --git a/time/time.h b/time/time.h
index 7f98338abe..0fb1416aad 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__));