select: overhaul for time64
[musl.git] / src / time / timer_gettime.c
blob21c9d32c3fe52e7502f10af91380ce4faead2c55
1 #include <time.h>
2 #include <limits.h>
3 #include "pthread_impl.h"
5 int timer_gettime(timer_t t, struct itimerspec *val)
7 if ((intptr_t)t < 0) {
8 pthread_t td = (void *)((uintptr_t)t << 1);
9 t = (void *)(uintptr_t)(td->timer_id & INT_MAX);
11 #ifdef SYS_timer_gettime64
12 int r = -ENOSYS;
13 if (sizeof(time_t) > 4)
14 r = __syscall(SYS_timer_gettime64, t, val);
15 if (SYS_timer_gettime == SYS_timer_gettime64 || r!=-ENOSYS)
16 return __syscall_ret(r);
17 long val32[4];
18 r = __syscall(SYS_timer_gettime, t, val32);
19 if (!r) {
20 val->it_interval.tv_sec = val32[0];
21 val->it_interval.tv_nsec = val32[1];
22 val->it_value.tv_sec = val32[2];
23 val->it_value.tv_nsec = val32[3];
25 return __syscall_ret(r);
26 #endif
27 return syscall(SYS_timer_gettime, t, val);