xref: /haiku/src/system/libroot/posix/sys/getrusage.c (revision 21258e2674226d6aa732321b6f8494841895af5f)
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 
13 
14 int
15 getrusage(int who, struct rusage *rusage)
16 {
17 	team_usage_info info;
18 
19 	if (get_team_usage_info(B_CURRENT_TEAM, who, &info) != B_OK) {
20 		__set_errno(B_BAD_VALUE);
21 		return -1;
22 	}
23 
24 	rusage->ru_utime.tv_sec = info.user_time / 1000000;
25 	rusage->ru_utime.tv_usec = info.user_time % 1000000;
26 
27 	rusage->ru_stime.tv_sec = info.kernel_time / 1000000;
28 	rusage->ru_stime.tv_usec = info.kernel_time % 1000000;
29 
30 	return 0;
31 }
32 
33