From 73266881ff3b5f5cecf1f57b155fc16566adff9e Mon Sep 17 00:00:00 2001 From: Peter Avalos Date: Sun, 15 Mar 2009 01:16:52 -1000 Subject: [PATCH] Sync times() with FreeBSD: * The times(3) function returns the number of CLK_TCKs since the startup time, not since the UNIX Epoch. * Make the returnvalue of times(3) insensitive to changes in wall-clock. --- lib/libc/gen/times.3 | 19 ++++++++++--------- lib/libc/gen/times.c | 13 ++++++------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/libc/gen/times.3 b/lib/libc/gen/times.3 index b40be8fa92..a52bdc1872 100644 --- a/lib/libc/gen/times.3 +++ b/lib/libc/gen/times.3 @@ -9,10 +9,6 @@ .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. @@ -30,10 +26,10 @@ .\" SUCH DAMAGE. .\" .\" @(#)times.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD: src/lib/libc/gen/times.3,v 1.4.2.4 2001/12/14 18:33:51 ru Exp $ +.\" $FreeBSD: src/lib/libc/gen/times.3,v 1.12 2008/12/01 15:27:00 keramida Exp $ .\" $DragonFly: src/lib/libc/gen/times.3,v 1.2 2003/06/17 04:26:42 dillon Exp $ .\" -.Dd June 4, 1993 +.Dd December 1, 2008 .Dt TIMES 3 .Os .Sh NAME @@ -57,9 +53,13 @@ The .Fn times function returns the value of time in .Dv CLK_TCK Ns 's -of a second since -0 hours, 0 minutes, 0 seconds, January 1, 1970, Coordinated Universal -Time. +of a second since the system startup time. +The current value of +.Dv CLK_TCK , +the frequency of the statistics clock in ticks per second, may be +obtained through the +.Xr sysconf 3 +interface. .Pp It also fills in the structure pointed to by .Fa tp @@ -136,6 +136,7 @@ and .Xr getrusage 2 , .Xr gettimeofday 2 , .Xr wait 2 , +.Xr sysconf 3 , .Xr clocks 7 .Sh STANDARDS The diff --git a/lib/libc/gen/times.c b/lib/libc/gen/times.c index 7c7518a6b8..69d4daf65e 100644 --- a/lib/libc/gen/times.c +++ b/lib/libc/gen/times.c @@ -10,10 +10,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -31,6 +27,7 @@ * SUCH DAMAGE. * * @(#)times.c 8.1 (Berkeley) 6/4/93 + * $FreeBSD: src/lib/libc/gen/times.c,v 1.4 2007/01/09 00:27:55 imp Exp $ * $DragonFly: src/lib/libc/gen/times.c,v 1.4 2005/11/13 00:07:42 swildner Exp $ */ @@ -49,7 +46,8 @@ clock_t times(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); @@ -59,7 +57,8 @@ times(struct tms *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); } -- 2.11.4.GIT