]>
Commit | Line | Data |
---|---|---|
0ecb606c | 1 | /* Copyright (C) 1996-1998,2001,2002,2003,2006 Free Software Foundation, Inc. |
478b92f0 UD |
2 | This file is part of the GNU C Library. |
3 | Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. | |
503054c0 | 4 | |
478b92f0 | 5 | The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
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. | |
503054c0 | 9 | |
478b92f0 UD |
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 | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
503054c0 | 14 | |
41bdb6e2 AJ |
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 | |
18 | 02111-1307 USA. */ | |
503054c0 RM |
19 | |
20 | #include <errno.h> | |
cb0509a8 | 21 | #include <signal.h> |
8be918b7 | 22 | #include <stddef.h> /* For NULL. */ |
842907c6 | 23 | #include <sys/time.h> |
503054c0 | 24 | #include <sys/select.h> |
6ee8d334 | 25 | #include <sysdep-cancel.h> |
503054c0 | 26 | |
0ecb606c | 27 | |
503054c0 RM |
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 | |
cb0509a8 UD |
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 | |
33 | errors. */ | |
0ecb606c JJ |
34 | int |
35 | __pselect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, | |
36 | const struct timespec *timeout, const sigset_t *sigmask) | |
503054c0 RM |
37 | { |
38 | struct timeval tval; | |
39 | int retval; | |
cb0509a8 | 40 | sigset_t savemask; |
503054c0 | 41 | |
db7ffaa3 | 42 | /* Change nanosecond number to microseconds. This might mean losing |
503054c0 RM |
43 | precision and therefore the `pselect` should be available. But |
44 | for now it is hardly found. */ | |
45 | if (timeout != NULL) | |
46 | TIMESPEC_TO_TIMEVAL (&tval, timeout); | |
47 | ||
cb0509a8 UD |
48 | /* The setting and restoring of the signal mask and the select call |
49 | should be an atomic operation. This can't be done without kernel | |
50 | help. */ | |
db7ffaa3 UD |
51 | if (sigmask != NULL) |
52 | __sigprocmask (SIG_SETMASK, sigmask, &savemask); | |
53 | ||
7a114794 UD |
54 | /* Note the pselect() is a cancellation point. But since we call |
55 | select() which itself is a cancellation point we do not have | |
56 | to do anything here. */ | |
503054c0 RM |
57 | retval = __select (nfds, readfds, writefds, exceptfds, |
58 | timeout != NULL ? &tval : NULL); | |
db7ffaa3 UD |
59 | |
60 | if (sigmask != NULL) | |
61 | __sigprocmask (SIG_SETMASK, &savemask, NULL); | |
503054c0 RM |
62 | |
63 | return retval; | |
64 | } | |
0ecb606c | 65 | #ifndef __pselect |
503054c0 | 66 | weak_alias (__pselect, pselect) |
e5e45b53 | 67 | strong_alias (__pselect, __libc_pselect) |
0ecb606c JJ |
68 | /* __select handles cancellation. */ |
69 | LIBC_CANCEL_HANDLED (); | |
70 | #endif |