summaryrefslogtreecommitdiff
path: root/src/misc/getrusage.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/misc/getrusage.c')
-rw-r--r--src/misc/getrusage.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/misc/getrusage.c b/src/misc/getrusage.c
new file mode 100644
index 00000000..1b8850f9
--- /dev/null
+++ b/src/misc/getrusage.c
@@ -0,0 +1,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;
+}