1 #include <sys/resource.h>
6 int getrusage(int who
, struct rusage
*ru
)
9 #ifdef SYS_getrusage_time64
11 r
= __syscall(SYS_getrusage_time64
, who
, kru64
);
13 ru
->ru_utime
= (struct timeval
)
14 { .tv_sec
= kru64
[0], .tv_usec
= kru64
[1] };
15 ru
->ru_stime
= (struct timeval
)
16 { .tv_sec
= kru64
[2], .tv_usec
= kru64
[3] };
17 char *slots
= (char *)&ru
->ru_maxrss
;
18 for (int i
=0; i
<14; i
++)
19 *(long *)(slots
+ i
*sizeof(long)) = kru64
[4+i
];
21 if (SYS_getrusage_time64
== SYS_getrusage
|| r
!= -ENOSYS
)
22 return __syscall_ret(r
);
24 char *dest
= (char *)&ru
->ru_maxrss
- 4*sizeof(long);
25 r
= __syscall(SYS_getrusage
, who
, dest
);
26 if (!r
&& sizeof(time_t) > sizeof(long)) {
28 memcpy(kru
, dest
, 4*sizeof(long));
29 ru
->ru_utime
= (struct timeval
)
30 { .tv_sec
= kru
[0], .tv_usec
= kru
[1] };
31 ru
->ru_stime
= (struct timeval
)
32 { .tv_sec
= kru
[2], .tv_usec
= kru
[3] };
34 return __syscall_ret(r
);