[RFC v3 05/23] sysdeps/timespec_get: Use clock_gettime64 if avaliable
Lukasz Majewski
lukma@denx.de
Wed Jul 17 12:23:00 GMT 2019
Hi Alistair,
> This will break other 32-bit targets
>
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> ---
> sysdeps/unix/sysv/linux/timespec_get.c | 37
> +++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1
> deletion(-)
>
> diff --git a/sysdeps/unix/sysv/linux/timespec_get.c
> b/sysdeps/unix/sysv/linux/timespec_get.c index 52080ddf08..78fa2aba1b
> 100644 --- a/sysdeps/unix/sysv/linux/timespec_get.c
> +++ b/sysdeps/unix/sysv/linux/timespec_get.c
> @@ -24,6 +24,36 @@
> #endif
> #include <sysdep-vdso.h>
>
> +
> +#if __WORDSIZE == 32
> +int
> +__timespec_get (struct timespec *ts, int base)
> +{
> + int ret;
> +
> +#ifdef __NR_clock_gettime64
> + struct __timespec64 ts64;
> + ret = INTERNAL_VSYSCALL (clock_gettime64, err, 2, CLOCK_REALTIME,
> &ts64); +
> + ts->tv_sec = ts64.tv_sec;
> + ts->tv_nsec = ts64.tv_nsec;
> +
You may consider using following helper functions (which are the part
of Y2038 support): [1]
> + if (! in_time_t_range (ts->tv_sec))
> + {
> + __set_errno (EOVERFLOW);
> + return -1;
> + }
> +#endif
> +
> +#ifndef __ASSUME_TIME64_SYSCALLS
> + ret = INTERNAL_VSYSCALL (clock_gettime, err, 2, CLOCK_REALTIME,
> ts); +#endif
> +
> + return ret;
> +}
> +
> +#else
> +
> /* Set TS to calendar time based in time base BASE. */
> int
> timespec_get (struct timespec *ts, int base)
> @@ -33,9 +63,13 @@ timespec_get (struct timespec *ts, int base)
> int res;
> INTERNAL_SYSCALL_DECL (err);
> case TIME_UTC:
> +#if __WORDSIZE == 32
> + res = __timespec_get (*ts, base);
> +#else
> res = INTERNAL_VSYSCALL (clock_gettime, err, 2,
> CLOCK_REALTIME, ts); +#endif
> if (INTERNAL_SYSCALL_ERROR_P (res, err))
> - return 0;
> + return 0;
> break;
>
> default:
> @@ -44,3 +78,4 @@ timespec_get (struct timespec *ts, int base)
>
> return base;
> }
> +#endif
Note:
[1] - https://github.com/lmajewski/y2038_glibc/commit/12ac380db090219aac4ed8b0ef179b9fcc4c296e
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20190717/941434d3/attachment.sig>
More information about the Libc-alpha
mailing list