• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <time.h>
2 #include <limits.h>
3 #include "pthread_impl.h"
4 
5 #define IS32BIT(x) !((x)+0x80000000ULL>>32)
6 
timer_settime(timer_t t,int flags,const struct itimerspec * restrict val,struct itimerspec * restrict old)7 int timer_settime(timer_t t, int flags, const struct itimerspec *restrict val, struct itimerspec *restrict old)
8 {
9 	if ((intptr_t)t < 0) {
10 		pthread_t td = (void *)((uintptr_t)t << 1);
11 		t = (void *)(uintptr_t)(td->timer_id & INT_MAX);
12 	}
13 #ifdef SYS_timer_settime64
14 	time_t is = val->it_interval.tv_sec, vs = val->it_value.tv_sec;
15 	long ins = val->it_interval.tv_nsec, vns = val->it_value.tv_nsec;
16 	int r = -ENOSYS;
17 	if (SYS_timer_settime == SYS_timer_settime64
18 	    || !IS32BIT(is) || !IS32BIT(vs) || (sizeof(time_t)>4 && old))
19 		r = __syscall(SYS_timer_settime64, t, flags,
20 			((long long[]){is, ins, vs, vns}), old);
21 	if (SYS_timer_settime == SYS_timer_settime64 || r!=-ENOSYS)
22 		return __syscall_ret(r);
23 	if (!IS32BIT(is) || !IS32BIT(vs))
24 		return __syscall_ret(-ENOTSUP);
25 	long old32[4];
26 	r = __syscall(SYS_timer_settime, t, flags,
27 		((long[]){is, ins, vs, vns}), old32);
28 	if (!r && old) {
29 		old->it_interval.tv_sec = old32[0];
30 		old->it_interval.tv_nsec = old32[1];
31 		old->it_value.tv_sec = old32[2];
32 		old->it_value.tv_nsec = old32[3];
33 	}
34 	return __syscall_ret(r);
35 #endif
36 	return syscall(SYS_timer_settime, t, flags, val, old);
37 }
38