diff options
author | phk <phk@FreeBSD.org> | 2005-03-08 08:12:35 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 2005-03-08 08:12:35 +0000 |
commit | abe23c253887ff4cb8bfa13dc5a20a4e936fa947 (patch) | |
tree | 601d4285b1bceb0afb7b48eb7dc4c943f97fe997 /lib/libc | |
parent | 9719ee7af7c8b60de76c62724d80f8113c15d152 (diff) | |
download | FreeBSD-src-abe23c253887ff4cb8bfa13dc5a20a4e936fa947.zip FreeBSD-src-abe23c253887ff4cb8bfa13dc5a20a4e936fa947.tar.gz |
Make the returnvalue of times(3) insensitive to changes in wall-clock.
PR: 78537
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/gen/times.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/libc/gen/times.c b/lib/libc/gen/times.c index c7de17e..dd31524 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); } |