1 /* Copyright (C) 1996-1998,2001-2003,2006,2011 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 #include <stddef.h> /* For NULL. */
24 #include <sys/select.h>
25 #include <sysdep-cancel.h>
28 /* Check the first NFDS descriptors each in READFDS (if not NULL) for read
29 readiness, in WRITEFDS (if not NULL) for write readiness, and in EXCEPTFDS
30 (if not NULL) for exceptional conditions. If TIMEOUT is not NULL, time out
31 after waiting the interval specified therein. Additionally set the sigmask
32 SIGMASK for this call. Returns the number of ready descriptors, or -1 for
35 __pselect (int nfds
, fd_set
*readfds
, fd_set
*writefds
, fd_set
*exceptfds
,
36 const struct timespec
*timeout
, const sigset_t
*sigmask
)
42 /* Change nanosecond number to microseconds. This might mean losing
43 precision and therefore the `pselect` should be available. But
44 for now it is hardly found. */
47 /* Catch bugs which would be hidden by the TIMESPEC_TO_TIMEVAL
48 computations. The division by 1000 truncates values. */
49 if (__builtin_expect (timeout
->tv_nsec
< 0, 0))
55 TIMESPEC_TO_TIMEVAL (&tval
, timeout
);
58 /* The setting and restoring of the signal mask and the select call
59 should be an atomic operation. This can't be done without kernel
62 __sigprocmask (SIG_SETMASK
, sigmask
, &savemask
);
64 /* Note the pselect() is a cancellation point. But since we call
65 select() which itself is a cancellation point we do not have
66 to do anything here. */
67 retval
= __select (nfds
, readfds
, writefds
, exceptfds
,
68 timeout
!= NULL
? &tval
: NULL
);
71 __sigprocmask (SIG_SETMASK
, &savemask
, NULL
);
76 weak_alias (__pselect
, pselect
)
77 strong_alias (__pselect
, __libc_pselect
)
78 /* __select handles cancellation. */
79 LIBC_CANCEL_HANDLED ();