xref: /aosp_15_r20/external/musl/src/select/ppoll.c (revision c9945492fdd68bbe62686c5b452b4dc1be3f8453)
1 #define _BSD_SOURCE
2 #include <poll.h>
3 #include <signal.h>
4 #include <errno.h>
5 #include "syscall.h"
6 
7 #define IS32BIT(x) !((x)+0x80000000ULL>>32)
8 #define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
9 
ppoll(struct pollfd * fds,nfds_t n,const struct timespec * to,const sigset_t * mask)10 int ppoll(struct pollfd *fds, nfds_t n, const struct timespec *to, const sigset_t *mask)
11 {
12 	time_t s = to ? to->tv_sec : 0;
13 	long ns = to ? to->tv_nsec : 0;
14 #ifdef SYS_ppoll_time64
15 	int r = -ENOSYS;
16 	if (SYS_ppoll == SYS_ppoll_time64 || !IS32BIT(s))
17 		r = __syscall_cp(SYS_ppoll_time64, fds, n,
18 			to ? ((long long[]){s, ns}) : 0,
19 			mask, _NSIG/8);
20 	if (SYS_ppoll == SYS_ppoll_time64 || r != -ENOSYS)
21 		return __syscall_ret(r);
22 	s = CLAMP(s);
23 #endif
24 	return syscall_cp(SYS_ppoll, fds, n,
25 		to ? ((long[]){s, ns}) : 0, mask, _NSIG/8);
26 }
27