xref: /csrg-svn/lib/libc/gen/times.c (revision 45139)
1 /*-
2  * Copyright (c) 1990 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #if defined(LIBC_SCCS) && !defined(lint)
9 static char sccsid[] = "@(#)times.c	5.3 (Berkeley) 08/27/90";
10 #endif /* LIBC_SCCS and not lint */
11 
12 #include <sys/time.h>
13 #include <sys/times.h>
14 #include <sys/resource.h>
15 
16 clock_t
17 times(tmsp)
18 	register struct tms *tmsp;
19 {
20 	struct rusage ru;
21 	clock_t scale60();
22 
23 	if (getrusage(RUSAGE_SELF, &ru) < 0)
24 		return ((clock_t)-1);
25 	tmsp->tms_utime = scale60(&ru.ru_utime);
26 	tmsp->tms_stime = scale60(&ru.ru_stime);
27 	if (getrusage(RUSAGE_CHILDREN, &ru) < 0)
28 		return ((clock_t)-1);
29 	tmsp->tms_cutime = scale60(&ru.ru_utime);
30 	tmsp->tms_cstime = scale60(&ru.ru_stime);
31 	return ((clock_t)0);
32 }
33 
34 static clock_t
35 scale60(tvp)
36 	register struct timeval *tvp;
37 {
38 	return (tvp->tv_sec * 60 + tvp->tv_usec / 16667);
39 }
40