1 /* Copyright (C) 2006-2015 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2006.
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.
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.
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 <http://www.gnu.org/licenses/>. */
22 #include <stddef.h> /* For NULL. */
24 #include <sysdep-cancel.h>
28 ppoll (struct pollfd
*fds
, nfds_t nfds
, const struct timespec
*timeout
,
29 const sigset_t
*sigmask
)
33 /* poll uses a simple millisecond value. Convert it. */
36 if (timeout
->tv_sec
< 0
37 || timeout
->tv_nsec
< 0 || timeout
->tv_nsec
>= 1000000000)
43 if (timeout
->tv_sec
> INT_MAX
/ 1000
44 || (timeout
->tv_sec
== INT_MAX
/ 1000
45 && ((timeout
->tv_nsec
+ 999999) / 1000000 > INT_MAX
% 1000)))
46 /* We cannot represent the timeout in an int value. Wait
50 tval
= (timeout
->tv_sec
* 1000
51 + (timeout
->tv_nsec
+ 999999) / 1000000);
54 /* The setting and restoring of the signal mask and the select call
55 should be an atomic operation. This can't be done without kernel
59 __sigprocmask (SIG_SETMASK
, sigmask
, &savemask
);
61 /* Note the ppoll() is a cancellation point. But since we call
62 poll() which itself is a cancellation point we do not have
63 to do anything here. */
64 int retval
= __poll (fds
, nfds
, tval
);
67 __sigprocmask (SIG_SETMASK
, &savemask
, NULL
);
73 /* __poll handles cancellation. */
74 LIBC_CANCEL_HANDLED ();
75 libc_hidden_def (ppoll
);