TIOCGPGRP copies an int out of the kernel
[unix-history] / usr / src / lib / libc / gen / times.c
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* %sccs.include.redist.c%
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)times.c 5.4 (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
#include <sys/time.h>
#include <sys/times.h>
#include <sys/resource.h>
/*
* Convert usec to clock ticks; could do (usec * CLK_TCK) / 1000000,
* but this would overflow if we switch to nanosec.
*/
#define CONVTCK(r) (r.tv_sec * CLK_TCK + r.tv_usec / (1000000 / CLK_TCK))
clock_t
times(tp)
register struct tms *tp;
{
struct rusage ru;
struct timeval t;
if (getrusage(RUSAGE_SELF, &ru) < 0)
return ((clock_t)-1);
tp->tms_utime = CONVTCK(ru.ru_utime);
tp->tms_stime = CONVTCK(ru.ru_stime);
if (getrusage(RUSAGE_CHILDREN, &ru) < 0)
return ((clock_t)-1);
tp->tms_cutime = CONVTCK(ru.ru_utime);
tp->tms_cstime = CONVTCK(ru.ru_stime);
if (gettimeofday(&t, (struct timezone *)0))
return ((clock_t)-1);
return ((clock_t)(CONVTCK(t)));
}