powerpc64le: use common fmaf128 implementation
[glibc.git] / io / ppoll.c
blob2b880426fccd612c4d9f62d0985b68dd45a9a1f7
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.
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 <https://www.gnu.org/licenses/>. */
19 #include <errno.h>
20 #include <limits.h>
21 #include <signal.h>
22 #include <stddef.h> /* For NULL. */
23 #include <sys/poll.h>
24 #include <sysdep-cancel.h>
25 #include <time.h>
28 int
29 ppoll (struct pollfd *fds, nfds_t nfds, const struct timespec *timeout,
30 const sigset_t *sigmask)
32 int tval = -1;
34 /* poll uses a simple millisecond value. Convert it. */
35 if (timeout != NULL)
37 if (timeout->tv_sec < 0 || ! valid_nanoseconds (timeout->tv_nsec))
39 __set_errno (EINVAL);
40 return -1;
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
47 forever. */
48 tval = -1;
49 else
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
56 help. */
57 sigset_t savemask;
58 if (sigmask != NULL)
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);
66 if (sigmask != NULL)
67 __sigprocmask (SIG_SETMASK, &savemask, NULL);
69 return retval;
72 #ifndef ppoll
73 libc_hidden_def (ppoll);
74 #endif