[RFC,31/52] Y2038: add function __gettimeofday_t64

Message ID 20170907224219.12483-32-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.
Implementing a 64-bit settimeofday requires adding a new
file to build under time/ and we cannot name that new file
'settimeofday.c' or it will break the 32-bit settimeofday
symbol, so we call it 'settimeofday64.c'.

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

Patch

diff --git a/sysdeps/unix/sysv/linux/gettimeofday.c b/sysdeps/unix/sysv/linux/gettimeofday.c
index 6afa407ac4..5ebbddef4f 100644
--- a/sysdeps/unix/sysv/linux/gettimeofday.c
+++ b/sysdeps/unix/sysv/linux/gettimeofday.c
@@ -37,3 +37,29 @@  __gettimeofday (struct timeval *tv, struct timezone *tz)
 libc_hidden_def (__gettimeofday)
 weak_alias (__gettimeofday, gettimeofday)
 libc_hidden_weak (gettimeofday)
+
+/* 64-bit time version */
+
+extern int __y2038_linux_support;
+
+int
+__gettimeofday_t64 (struct __timeval64 *tv, struct timezone *tz)
+{
+  struct timeval tv32;
+  int result;
+
+  if (__y2038_linux_support)
+    {
+      /* TODO: implement using 64-bit time syscall */
+    }
+
+  result = INLINE_VSYSCALL (gettimeofday, 2, &tv32, tz);
+
+  if (result == 0)
+    {
+      tv->tv_sec = tv32.tv_sec;
+      tv->tv_usec = tv32.tv_usec;
+    }
+
+  return result;
+}
diff --git a/time/Versions b/time/Versions
index 3dca51abcb..7daf158a8b 100644
--- a/time/Versions
+++ b/time/Versions
@@ -73,5 +73,6 @@  libc {
     __timespec_get64;
     __time_t64;
     __stime_t64;
+    __gettimeofday_t64;
   }
 }
diff --git a/time/gettimeofday.c b/time/gettimeofday.c
index 1d675b6b23..b21d7d4b71 100644
--- a/time/gettimeofday.c
+++ b/time/gettimeofday.c
@@ -32,3 +32,13 @@  weak_alias (__gettimeofday, gettimeofday)
 libc_hidden_weak (gettimeofday)
 
 stub_warning (gettimeofday)
+
+/* 64-bit time version */
+
+int
+__gettimeofday_t64 (struct timeval *tv, struct timezone *tz)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (__gettimeofday_t64)