This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[RFC 3/7] y2038: clock_settime: Provide __clock_settime64 implementation for linux
- From: Lukasz Majewski <lukma at denx dot de>
- To: libc-alpha at sourceware dot org, Joseph Myers <joseph at codesourcery dot com>
- Cc: Paul Eggert <eggert at cs dot ucla dot edu>, Zack Weinberg <zackw at panix dot com>, Lukasz Majewski <lukma at denx dot de>
- Date: Wed, 27 Mar 2019 09:52:06 +0100
- Subject: [RFC 3/7] y2038: clock_settime: Provide __clock_settime64 implementation for linux
- References: <20190327085210.22019-1-lukma@denx.de>
* include/time.h: Remove __clock_settime typeof
* include/time.h: Add __clock_settime64 definition according to __TIMESIZE
* sysdeps/unix/sysv/linux/clock_settime.c: Remove clock_settime alias
* sysdeps/unix/sysv/linux/clock_settime.c:
Add clock_settime when __TIMESIZE != 64
Rewrite __clock_settime() to __clock_settime64 with explicit support for
64 bit time
---
include/time.h | 9 +++++++-
sysdeps/unix/sysv/linux/clock_settime.c | 40 +++++++++++++++++++++++----------
2 files changed, 36 insertions(+), 13 deletions(-)
diff --git a/include/time.h b/include/time.h
index 09231073b5..c8c0a6936e 100644
--- a/include/time.h
+++ b/include/time.h
@@ -22,7 +22,6 @@ libc_hidden_proto (strptime)
extern __typeof (clock_getres) __clock_getres;
extern __typeof (clock_gettime) __clock_gettime;
libc_hidden_proto (__clock_gettime)
-extern __typeof (clock_settime) __clock_settime;
extern __typeof (clock_nanosleep) __clock_nanosleep;
extern __typeof (clock_getcpuclockid) __clock_getcpuclockid;
@@ -103,6 +102,14 @@ extern __time64_t __timegm64 (struct tm *__tp) __THROW;
libc_hidden_proto (__timegm64)
#endif
+#if __TIMESIZE == 64
+# define __clock_settime64 clock_settime
+#else
+extern int __clock_settime64 (clockid_t clock_id,
+ const struct __timespec64 *tp);
+libc_hidden_proto (__clock_settime64)
+#endif
+
/* Compute the `struct tm' representation of T,
offset OFFSET seconds east of UTC,
and store year, yday, mon, mday, wday, hour, min, sec into *TP.
diff --git a/sysdeps/unix/sysv/linux/clock_settime.c b/sysdeps/unix/sysv/linux/clock_settime.c
index d837e3019c..5b7ab7fcb3 100644
--- a/sysdeps/unix/sysv/linux/clock_settime.c
+++ b/sysdeps/unix/sysv/linux/clock_settime.c
@@ -19,19 +19,35 @@
#include <sysdep.h>
#include <time.h>
-#include "kernel-posix-cpu-timers.h"
+int
+__clock_settime64 (clockid_t clock_id, const struct __timespec64 *tp)
+{
+ /* Make sure the time cvalue is OK. */
+ if (tp->tv_nsec < 0 || tp->tv_nsec >= 1000000000)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ return INLINE_SYSCALL_CALL (clock_settime, clock_id, tp);
+}
-/* Set CLOCK to value TP. */
+#if __TIMESIZE != 64
int
-__clock_settime (clockid_t clock_id, const struct timespec *tp)
+clock_settime (clockid_t clock_id, const struct timespec *tp)
{
- /* Make sure the time cvalue is OK. */
- if (tp->tv_nsec < 0 || tp->tv_nsec >= 1000000000)
- {
- __set_errno (EINVAL);
- return -1;
- }
-
- return INLINE_SYSCALL_CALL (clock_settime, clock_id, tp);
+ struct __timespec64 ts64;
+
+ if (! in_time_t_range (tp->tv_sec))
+ {
+ __set_errno (EOVERFLOW);
+ return -1;
+ }
+
+ valid_timespec_to_timespec64 (tp, &ts64);
+ return __clock_settime64 (clock_id, &ts64);
}
-weak_alias (__clock_settime, clock_settime)
+
+/* The clock_settime symbol needs to be public as librt is also
+ using it */
+#endif
--
2.11.0