1/*
2** Copyright 2004, J��r��me Duval, jerome.duval@free.fr.
3** Copyright 2004, Axel D��rfler, axeld@pinc-software.de. All rights reserved.
4** Distributed under the terms of the MIT License.
5*/
6
7#include <OS.h>
8#include <sys/resource.h>
9#include <errno.h>
10
11#include <errno_private.h>
12#include <symbol_versioning.h>
13
14
15// prototypes for the compiler
16int _getrusage_base(int who, struct rusage *rusage);
17int _getrusage_current(int who, struct rusage *rusage);
18
19
20int
21_getrusage_base(int who, struct rusage *rusage)
22{
23	team_usage_info info;
24
25	if (get_team_usage_info(B_CURRENT_TEAM, who, &info) != B_OK) {
26		__set_errno(B_BAD_VALUE);
27		return -1;
28	}
29
30	rusage->ru_utime.tv_sec = info.user_time / 1000000;
31	rusage->ru_utime.tv_usec = info.user_time % 1000000;
32
33	rusage->ru_stime.tv_sec = info.kernel_time / 1000000;
34	rusage->ru_stime.tv_usec = info.kernel_time % 1000000;
35
36	return 0;
37}
38
39
40int
41_getrusage_current(int who, struct rusage *rusage)
42{
43	int err = _getrusage_base(who, rusage);
44	if (err != -1) {
45		memset(&rusage->ru_maxrss, 0, sizeof(struct rusage) -
46			offsetof(struct rusage, ru_maxrss));
47	}
48	return err;
49}
50
51
52DEFINE_LIBROOT_KERNEL_SYMBOL_VERSION("_getrusage_base", "getrusage@", "BASE");
53DEFINE_LIBROOT_KERNEL_SYMBOL_VERSION("_getrusage_current", "getrusage@@",
54	"1_BETA3");
55