From 008aca9807ec0d052433d5231df2b11bfcf23251 Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Tue, 8 Mar 2005 08:12:35 +0000 Subject: Make the returnvalue of times(3) insensitive to changes in wall-clock. PR: 78537 --- lib/libc/gen/times.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/libc/gen/times.c b/lib/libc/gen/times.c index c7de17ee72a7..dd3152443543 100644 --- a/lib/libc/gen/times.c +++ b/lib/libc/gen/times.c @@ -53,7 +53,8 @@ times(tp) struct tms *tp; { struct rusage ru; - struct timeval t; + struct timespec t; + clock_t c; if (getrusage(RUSAGE_SELF, &ru) < 0) return ((clock_t)-1); @@ -63,7 +64,8 @@ times(tp) return ((clock_t)-1); tp->tms_cutime = CONVTCK(ru.ru_utime); tp->tms_cstime = CONVTCK(ru.ru_stime); - if (gettimeofday(&t, (struct timezone *)0)) + if (clock_gettime(CLOCK_MONOTONIC, &t)) return ((clock_t)-1); - return ((clock_t)(CONVTCK(t))); + c = t.tv_sec * CLK_TCK + t.tv_nsec / (1000000000 / CLK_TCK); + return (c); } -- cgit v1.2.3