Introduce time64 support.
[uclibc-ng.git] / libc / sysdeps / linux / common / pselect.c
blob23bdab5cfb955e4c98ac7d160a15255ebd1e855f
1 /* Copyright (C) 1996-1998,2001,2002,2003,2006 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
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/>. */
19 #include <features.h>
21 #ifdef __USE_XOPEN2K
23 #include <sys/syscall.h>
24 #include <sys/select.h>
25 #include <sys/time.h>
26 #include <signal.h>
27 #include <cancel.h>
29 static int __NC(pselect)(int nfds, fd_set *readfds, fd_set *writefds,
30 fd_set *exceptfds, const struct timespec *timeout,
31 const sigset_t *sigmask)
33 #ifdef __NR_pselect6
34 /* The Linux kernel can in some situations update the timeout value.
35 * We do not want that so use a local variable.
37 struct timespec _ts;
39 /* Note: the system call expects 7 values but on most architectures
40 we can only pass in 6 directly. If there is an architecture with
41 support for more parameters a new version of this file needs to
42 be created. */
43 struct {
44 __kernel_ulong_t ss;
45 __kernel_size_t ss_len;
46 } data;
48 if (timeout != NULL) {
49 _ts = *timeout;
50 timeout = &_ts;
53 if (sigmask != NULL) {
54 data.ss = (__kernel_ulong_t) sigmask;
55 data.ss_len = __SYSCALL_SIGSET_T_SIZE;
57 sigmask = (void *)&data;
59 #if defined(__UCLIBC_USE_TIME64__) && defined(__NR_pselect6_time64)
60 return INLINE_SYSCALL(pselect6_time64, 6, nfds, readfds, writefds, exceptfds, timeout, sigmask);
61 #else
62 return INLINE_SYSCALL(pselect6, 6, nfds, readfds, writefds, exceptfds, timeout, sigmask);
63 #endif
64 #else
65 struct timeval tval;
66 int retval;
67 sigset_t savemask;
69 /* Change nanosecond number to microseconds. This might mean losing
70 precision and therefore the `pselect` should be available. But
71 for now it is hardly found. */
72 if (timeout != NULL)
73 TIMESPEC_TO_TIMEVAL (&tval, timeout);
75 /* The setting and restoring of the signal mask and the select call
76 should be an atomic operation. This can't be done without kernel
77 help. */
78 if (sigmask != NULL)
79 sigprocmask (SIG_SETMASK, sigmask, &savemask);
81 /* The comment below does not apply on uClibc, since we use __select_nocancel */
82 /* Note the pselect() is a cancellation point. But since we call
83 select() which itself is a cancellation point we do not have
84 to do anything here. */
85 retval = __NC(select)(nfds, readfds, writefds, exceptfds,
86 timeout != NULL ? &tval : NULL);
88 if (sigmask != NULL)
89 sigprocmask (SIG_SETMASK, &savemask, NULL);
91 return retval;
92 #endif
95 CANCELLABLE_SYSCALL(int, pselect, (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
96 const struct timespec *timeout, const sigset_t *sigmask),
97 (nfds, readfds, writefds, exceptfds, timeout, sigmask))
99 #endif