From 4bbed305da2514696cffa25e1ecf3bc6bbe407e0 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Sun, 6 Dec 2015 05:28:11 +0000 Subject: [PATCH] times.test: workaround buggy libc * tests/times.c: Include . (main): On systems where user's and kernel's long types are the same, prefer direct times syscall over libc's times function because the latter is more prone to return value truncation. --- tests/times.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/tests/times.c b/tests/times.c index 0ec30198..f0e7086b 100644 --- a/tests/times.c +++ b/tests/times.c @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -61,16 +62,32 @@ main (void) } struct tms tbuf; + unsigned long long llres; + + /* + * On systems where user's and kernel's long types are the same, + * prefer direct times syscall over libc's times function because + * the latter is more prone to return value truncation. + */ +#if !defined __NR_times \ + || defined LINUX_MIPSN32 \ + || defined __x86_64__ && defined __ILP32__ clock_t res = times(&tbuf); - if (res == (clock_t) -1) + if ((clock_t) -1 == res) return 77; - - unsigned long long llres; - if (sizeof(llres) > sizeof(res)) + if (sizeof(res) < sizeof(unsigned long long)) llres = (unsigned long) res; else llres = res; +#else + long res = syscall(__NR_times, &tbuf); + + if (-1L == res) + return 77; + else + llres = (unsigned long) res; +#endif printf("times({tms_utime=%llu, tms_stime=%llu, ", (unsigned long long) tbuf.tms_utime, -- 2.40.0