summaryrefslogtreecommitdiff
path: root/src/misc/getrusage.c
blob: 1b8850f99582ccbbbbe308e82824cb36c79b5d54 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <sys/resource.h>
#include <string.h>
#include "syscall.h"

/* this is a huge hack to make up for the kernel's stupid 32bit time_t
 * without having to recopy the whole rusage structure ourselves.. */

int getrusage(int who, struct rusage *ru)
{
	struct { long tv_sec, tv_usec; } ktv[2];
	char *fakeaddr = ((char *)ru + sizeof(struct timeval [2]) - sizeof ktv);
	if (syscall2(__NR_getrusage, who, (long)fakeaddr) < 0)
		return -1;
	memcpy(ktv, fakeaddr, sizeof ktv);
	ru->ru_utime.tv_sec  = ktv[0].tv_sec;
	ru->ru_utime.tv_usec = ktv[0].tv_usec;
	ru->ru_stime.tv_sec  = ktv[1].tv_sec;
	ru->ru_stime.tv_usec = ktv[1].tv_usec;
	return 0;
}