Update.
[glibc.git] / sysdeps / generic / pselect.c
blobdab4d754f208310a4ae011b28ffce0d5cb56ebb9
1 /* Copyright (C) 1996, 1997, 1998 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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #include <errno.h>
21 #include <signal.h>
22 #include <sys/time.h>
23 #include <sys/select.h>
25 /* Check the first NFDS descriptors each in READFDS (if not NULL) for read
26 readiness, in WRITEFDS (if not NULL) for write readiness, and in EXCEPTFDS
27 (if not NULL) for exceptional conditions. If TIMEOUT is not NULL, time out
28 after waiting the interval specified therein. Additionally set the sigmask
29 SIGMASK for this call. Returns the number of ready descriptors, or -1 for
30 errors. */
31 int
32 __pselect (nfds, readfds, writefds, exceptfds, timeout, sigmask)
33 int nfds;
34 fd_set *readfds;
35 fd_set *writefds;
36 fd_set *exceptfds;
37 const struct timespec *timeout;
38 const sigset_t *sigmask;
40 struct timeval tval;
41 int retval;
42 sigset_t savemask;
44 /* Change nanosecond number to microseconds. This may loose
45 precision and therefore the `pselect` should be available. But
46 for now it is hardly found. */
47 if (timeout != NULL)
48 TIMESPEC_TO_TIMEVAL (&tval, timeout);
50 /* The setting and restoring of the signal mask and the select call
51 should be an atomic operation. This can't be done without kernel
52 help. */
53 __sigprocmask (SIG_SETMASK, sigmask, &savemask);
54 retval = __select (nfds, readfds, writefds, exceptfds,
55 timeout != NULL ? &tval : NULL);
56 __sigprocmask (SIG_SETMASK, &savemask, NULL);
58 return retval;
60 weak_alias (__pselect, pselect)