1/* Copyright (C) 2006-2020 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2006.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#include <errno.h>
20#include <signal.h>
21#include <time.h>
22#include <sys/poll.h>
23#include <sysdep-cancel.h>
24#include <kernel-features.h>
25
26
27int
28__ppoll64 (struct pollfd *fds, nfds_t nfds, const struct __timespec64 *timeout,
29 const sigset_t *sigmask)
30{
31 /* The Linux kernel can in some situations update the timeout value.
32 We do not want that so use a local variable. */
33 struct __timespec64 tval;
34 if (timeout != NULL)
35 {
36 tval = *timeout;
37 timeout = &tval;
38 }
39
40#ifdef __ASSUME_TIME64_SYSCALLS
41# ifndef __NR_ppoll_time64
42# define __NR_ppoll_time64 __NR_ppoll
43# endif
44 return SYSCALL_CANCEL (ppoll_time64, fds, nfds, timeout, sigmask,
45 __NSIG_BYTES);
46#else
47# ifdef __NR_ppoll_time64
48 int ret = SYSCALL_CANCEL (ppoll_time64, fds, nfds, timeout, sigmask,
49 __NSIG_BYTES);
50 if (ret >= 0 || errno != ENOSYS)
51 return ret;
52# endif
53 struct timespec ts32;
54 if (timeout)
55 {
56 if (! in_time_t_range (timeout->tv_sec))
57 {
58 __set_errno (EOVERFLOW);
59 return -1;
60 }
61
62 ts32 = valid_timespec64_to_timespec (*timeout);
63 }
64
65 return SYSCALL_CANCEL (ppoll, fds, nfds, timeout ? &ts32 : NULL, sigmask,
66 __NSIG_BYTES);
67#endif
68}
69
70#if __TIMESIZE != 64
71libc_hidden_def (__ppoll64)
72
73int
74__ppoll (struct pollfd *fds, nfds_t nfds, const struct timespec *timeout,
75 const sigset_t *sigmask)
76{
77 struct __timespec64 ts64;
78 if (timeout)
79 ts64 = valid_timespec_to_timespec64 (*timeout);
80
81 return __ppoll64 (fds, nfds, timeout ? &ts64 : NULL, sigmask);
82}
83#endif
84strong_alias (__ppoll, ppoll)
85libc_hidden_def (ppoll)
86