X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fpselect.c;h=b544c7c321854e4426204a847b450ca9b8db2fb4;hb=fa915b528c85b90fd55839907f862a0d4cd273db;hp=4e7a7ed86e72690b677389ea9c0be99e5b93ecc3;hpb=9500a55f083bb8e55ee938e4532ae6baea702e6b;p=gnulib.git diff --git a/lib/pselect.c b/lib/pselect.c index 4e7a7ed86..b544c7c32 100644 --- a/lib/pselect.c +++ b/lib/pselect.c @@ -33,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, @@ -74,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