summaryrefslogtreecommitdiff
path: root/lib/pselect.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2012-10-04 00:15:42 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2012-10-04 00:15:42 -0700
commitbb1dfdadd507bb4b77595c87875ef807c101ed7b (patch)
treeeb92a2335896c34e76a9e19362049396b8d0483f /lib/pselect.c
parent88d69b7ddca305bb96d6e671300f6724e4f147dd (diff)
downloademacs-bb1dfdadd507bb4b77595c87875ef807c101ed7b.tar.gz
Merge from gnulib.
Diffstat (limited to 'lib/pselect.c')
-rw-r--r--lib/pselect.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/pselect.c b/lib/pselect.c
index d8ebc70f6c6..1b6d099dccf 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 <unistd.h>
+# 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