[RFC,28/52] Y2038: add function __time_t64

Message ID 20170907224219.12483-29-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.
These implementations use only 32-bit time kernel syscalls.

Therefore, stime() will always set errno to EOVERFLOW and return -1 for dates beyond Y2038.

Signed-off-by: Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
---
 sysdeps/posix/time.c           | 26 ++++++++++++++++++++++++++
 sysdeps/unix/sysv/linux/time.c | 22 ++++++++++++++++++++++
 time/Versions                  |  1 +
 time/time.c                    | 13 +++++++++++++
 4 files changed, 62 insertions(+)

Patch

diff --git a/sysdeps/posix/time.c b/sysdeps/posix/time.c
index 32ca177514..a4c4a03c55 100644
--- a/sysdeps/posix/time.c
+++ b/sysdeps/posix/time.c
@@ -38,3 +38,29 @@  time (time_t *t)
   return result;
 }
 libc_hidden_def (time)
+
+/* 64-bit time version */
+
+extern int __y2038_linux_support;
+
+__time64_t
+__time_t64 (__time64_t *t)
+{
+  struct timeval tv32;
+  __time64_t result;
+
+  if (__y2038_linux_support)
+  {
+    /* TODO: implement using 64-bit time syscall */
+  }
+
+  if (__gettimeofday (&tv32, (struct timezone *) NULL))
+    result = (__time64_t) -1;
+  else
+    result = (__time64_t) tv32.tv_sec;
+
+  if (t != NULL)
+    *t = result;
+
+  return result;
+}
diff --git a/sysdeps/unix/sysv/linux/time.c b/sysdeps/unix/sysv/linux/time.c
index 72d4040cbc..b6c7e61844 100644
--- a/sysdeps/unix/sysv/linux/time.c
+++ b/sysdeps/unix/sysv/linux/time.c
@@ -34,6 +34,28 @@  time (time_t *t)
 }
 libc_hidden_def (time)
 
+/* 64-BIT TIME VERSION */
+
+extern int __y2038_linux_support;
+
+__time64_t
+__time_t64 (__time64_t *t)
+{
+  INTERNAL_SYSCALL_DECL (err);
+  __time64_t res;
+
+  if (__y2038_linux_support)
+    {
+      /* TODO: implement using 64-bit time syscall */
+    }
+
+  res = INTERNAL_SYSCALL (time, err, 1, NULL);
+  /* There cannot be any error.  */
+  if (t != NULL)
+    *t = res;
+  return res;
+}
+
 #else
 
 # include <sysdeps/posix/time.c>
diff --git a/time/Versions b/time/Versions
index 3fe860862a..02dc8d6146 100644
--- a/time/Versions
+++ b/time/Versions
@@ -71,5 +71,6 @@  libc {
 
   GLIBC_Y2038 {
     __timespec_get64;
+    __time_t64;
   }
 }
diff --git a/time/time.c b/time/time.c
index e375035265..a487068468 100644
--- a/time/time.c
+++ b/time/time.c
@@ -31,3 +31,16 @@  time (time_t *timer)
 libc_hidden_def (time)
 
 stub_warning (time)
+
+/* 64-bit time version */
+
+__time64_t
+__time_t64 (__time64_ *timer)
+{
+  __set_errno (ENOSYS);
+
+  if (timer != NULL)
+    *timer = (__time64_t) -1;
+  return (__time64_t) -1;
+}
+libc_hidden_def (__time_t64)