diff --git a/src/kernel/libroot/posix/sys/times.c b/src/kernel/libroot/posix/sys/times.c index e43d0ac758..b47251787b 100644 --- a/src/kernel/libroot/posix/sys/times.c +++ b/src/kernel/libroot/posix/sys/times.c @@ -1,24 +1,39 @@ /* -** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. -** Distributed under the terms of the Haiku License. +** Copyright 2004, Jérô Duval, jerome.duval@free.fr. +** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. +** Distributed under the terms of the MIT License. */ - #include +#include +#include #include -#include clock_t times(struct tms *buffer) { - // ToDo: get some real values here! - buffer->tms_utime = 0; - buffer->tms_stime = 0; - buffer->tms_cutime = 0; - buffer->tms_cstime = 0; + team_usage_info info; + status_t err; + int32 clk_tck = 1000000 / CLK_TCK; /* to avoid overflow */ - return real_time_clock() * CLK_TCK; + if ((err = get_team_usage_info(B_CURRENT_TEAM, RUSAGE_SELF, &info)) != B_OK) { + errno = err; + return -1; + } + + buffer->tms_utime = info.user_time / clk_tck; + buffer->tms_stime = info.kernel_time / clk_tck; + + if ((err = get_team_usage_info(B_CURRENT_TEAM, RUSAGE_CHILDREN, &info)) != B_OK) { + errno = err; + return -1; + } + + buffer->tms_cutime = info.user_time / clk_tck; + buffer->tms_cstime = info.kernel_time / clk_tck; + + return system_time() / clk_tck; }