X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fpselect.c;h=32d55f2eb49df73aec2ebff33431af1784630189;hb=c43cc7b973f4daf0c59368ae52e130dfd12ce8d6;hp=22023151b1e59cc56c2eb7da5b5a22354af7d4a8;hpb=1602f0afed21be664fcf5c42d59db07cc22c56d6;p=gnulib.git diff --git a/lib/pselect.c b/lib/pselect.c index 22023151b..32d55f2eb 100644 --- a/lib/pselect.c +++ b/lib/pselect.c @@ -1,6 +1,6 @@ /* pselect - synchronous I/O multiplexing - Copyright 2011-2012 Free Software Foundation, Inc. + Copyright 2011-2014 Free Software Foundation, Inc. This file is part of gnulib. @@ -15,8 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + with this program; if not, see . */ /* written by Paul Eggert */ @@ -34,6 +33,8 @@ pointer parameter stands for no descriptors, an infinite timeout, or an unaffected signal mask. */ +#if !HAVE_PSELECT + int pselect (int nfds, fd_set *restrict rfds, fd_set *restrict wfds, fd_set *restrict xfds, @@ -75,3 +76,35 @@ pselect (int nfds, fd_set *restrict rfds, return select_result; } + +#else /* HAVE_PSELECT */ +# include +# undef pselect + +int +rpl_pselect (int nfds, fd_set *restrict rfds, + fd_set *restrict wfds, fd_set *restrict xfds, + struct timespec const *restrict timeout, + sigset_t const *restrict sigmask) +{ + int i; + + /* FreeBSD 8.2 has a bug: it does not always detect invalid fds. */ + if (nfds < 0 || nfds > FD_SETSIZE) + { + errno = EINVAL; + return -1; + } + for (i = 0; i < nfds; i++) + { + if (((rfds && FD_ISSET (i, rfds)) + || (wfds && FD_ISSET (i, wfds)) + || (xfds && FD_ISSET (i, xfds))) + && dup2 (i, i) != i) + return -1; + } + + return pselect (nfds, rfds, wfds, xfds, timeout, sigmask); +} + +#endif