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