[RFC,v5,05/21] sysdeps/clock_gettime: Use clock_gettime64 if avaliable
diff mbox series

Message ID 513e8d86c5d7a44fcf269f9c38883222fbbc168d.1567097252.git.alistair.francis@wdc.com
State New
Headers show
Series
  • RISC-V glibc port for the 32-bit
Related show

Commit Message

Alistair Francis Aug. 29, 2019, 4:50 p.m. UTC
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>

	* sysdeps/unix/sysv/linux/clock_gettime.c: Use clock_gettime64 if avaliable.
---
 include/time.h                          |  1 +
 sysdeps/unix/sysv/linux/clock_gettime.c | 48 ++++++++++++++++++++++++-
 2 files changed, 48 insertions(+), 1 deletion(-)

Patch
diff mbox series

diff --git a/include/time.h b/include/time.h
index 6d81f91384b..1e33f34e1f6 100644
--- a/include/time.h
+++ b/include/time.h
@@ -177,6 +177,7 @@  extern double __difftime (time_t time1, time_t time0);
 #define __clock_nanosleep_time64 __clock_nanosleep
 #define __nanosleep_time64 __nanosleep
 #define __nanosleep_nocancel_time64 __nanosleep_nocancel
+#define __clock_gettime64 __clock_gettime
 #endif
 
 /* Use in the clock_* functions.  Size of the field representing the
diff --git a/sysdeps/unix/sysv/linux/clock_gettime.c b/sysdeps/unix/sysv/linux/clock_gettime.c
index 5fc47fb7dc7..ea98af9bf1a 100644
--- a/sysdeps/unix/sysv/linux/clock_gettime.c
+++ b/sysdeps/unix/sysv/linux/clock_gettime.c
@@ -28,9 +28,55 @@ 
 
 /* Get current value of CLOCK and store it in TP.  */
 int
+__clock_gettime64 (clockid_t clock_id, struct timespec *tp)
+{
+#ifdef __ASSUME_TIME64_SYSCALLS
+# ifndef __NR_clock_gettime64
+#  define __NR_clock_gettime64 __NR_clock_gettime
+# endif
+   return INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp);
+#else
+   int ret;
+# ifdef __NR_clock_gettime64
+  ret = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp);
+
+  if (ret == 0 || errno != ENOSYS)
+    return ret;
+# endif /* __NR_clock_gettime64 */
+  struct timespec tp32;
+
+  ret = INLINE_VSYSCALL (clock_gettime, 2, clock_id, &tp32);
+
+  if (ret == 0 || errno != ENOSYS)
+    valid_timespec_to_timespec64(tp32, tp);
+
+  return ret;
+#endif /* __ASSUME_TIME64_SYSCALLS */
+}
+
+#if __TIMESIZE != 64
+int
 __clock_gettime (clockid_t clock_id, struct timespec *tp)
 {
-  return INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp);
+  int ret;
+  struct __timespec64 tp64;
+
+  ret = __clock_gettime64 (clock_id, &tp64);
+
+  if (ret == 0 || errno != ENOSYS)
+    {
+      if (! in_time_t_range (tp64.tv_sec))
+        {
+          __set_errno (EOVERFLOW);
+          return -1;
+        }
+
+      valid_timespec64_to_timespec(&tp64, tp);
+
+      return ret;
+    }
 }
+#endif
+
 weak_alias (__clock_gettime, clock_gettime)
 libc_hidden_def (__clock_gettime)