[[PATCH,RFC,2] 19/63] Y2038: add function __timespec_get64

Message ID 20180418201819.15952-20-albert.aribaud@3adev.fr
State New, archived
Headers

Commit Message

Albert ARIBAUD April 18, 2018, 8:17 p.m. UTC
  ---
 sysdeps/unix/sysv/linux/timespec_get.c | 41 ++++++++++++++++++++++++++++++++++
 time/Versions                          |  1 +
 2 files changed, 42 insertions(+)
  

Patch

diff --git a/sysdeps/unix/sysv/linux/timespec_get.c b/sysdeps/unix/sysv/linux/timespec_get.c
index b14a302ee9..b40bdedb57 100644
--- a/sysdeps/unix/sysv/linux/timespec_get.c
+++ b/sysdeps/unix/sysv/linux/timespec_get.c
@@ -44,3 +44,44 @@  timespec_get (struct timespec *ts, int base)
 
   return base;
 }
+
+/* 64-bit time version */
+
+extern int __y2038_linux_support;
+
+int
+__timespec_get64 (struct __timespec64 *ts, int base)
+{
+  switch (base)
+    {
+      int res;
+      INTERNAL_SYSCALL_DECL (err);
+    case TIME_UTC:
+      if (__y2038_linux_support)
+/* Check that we are built with a 64-bit-time kernel */
+#ifdef __NR_clock_nanosleep64
+        {
+          res = INTERNAL_VSYSCALL (clock_gettime64, err, 2, CLOCK_REALTIME, ts);
+        }
+      else
+#endif
+        {
+          res = -1;
+          __set_errno(ENOSYS);
+        }
+      if (res == -1 && errno == ENOSYS)
+        {
+          struct timespec ts32;
+          res = INTERNAL_VSYSCALL (clock_gettime, err, 2, CLOCK_REALTIME, &ts32);
+          if (INTERNAL_SYSCALL_ERROR_P (res, err))
+	    return 0;
+          timespec_to_timespec64(&ts32, ts);
+        }
+      break;
+
+    default:
+      return 0;
+    }
+
+  return base;
+}
diff --git a/time/Versions b/time/Versions
index 6fe9373913..668c134f12 100644
--- a/time/Versions
+++ b/time/Versions
@@ -78,5 +78,6 @@  libc {
     __clock_settime64;
     __clock_getres64;
     __clock_nanosleep64;
+    __timespec_get64;
   }
 }