diff options
| author | Paul Eggert | 2012-10-04 00:15:42 -0700 |
|---|---|---|
| committer | Paul Eggert | 2012-10-04 00:15:42 -0700 |
| commit | bb1dfdadd507bb4b77595c87875ef807c101ed7b (patch) | |
| tree | eb92a2335896c34e76a9e19362049396b8d0483f /lib/pselect.c | |
| parent | 88d69b7ddca305bb96d6e671300f6724e4f147dd (diff) | |
| download | emacs-bb1dfdadd507bb4b77595c87875ef807c101ed7b.tar.gz emacs-bb1dfdadd507bb4b77595c87875ef807c101ed7b.zip | |
Merge from gnulib.
Diffstat (limited to 'lib/pselect.c')
| -rw-r--r-- | lib/pselect.c | 34 |
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 @@ | |||
| 33 | pointer parameter stands for no descriptors, an infinite timeout, | 33 | pointer parameter stands for no descriptors, an infinite timeout, |
| 34 | or an unaffected signal mask. */ | 34 | or an unaffected signal mask. */ |
| 35 | 35 | ||
| 36 | #if !HAVE_PSELECT | ||
| 37 | |||
| 36 | int | 38 | int |
| 37 | pselect (int nfds, fd_set *restrict rfds, | 39 | pselect (int nfds, fd_set *restrict rfds, |
| 38 | fd_set *restrict wfds, fd_set *restrict xfds, | 40 | fd_set *restrict wfds, fd_set *restrict xfds, |
| @@ -74,3 +76,35 @@ pselect (int nfds, fd_set *restrict rfds, | |||
| 74 | 76 | ||
| 75 | return select_result; | 77 | return select_result; |
| 76 | } | 78 | } |
| 79 | |||
| 80 | #else /* HAVE_PSELECT */ | ||
| 81 | # include <unistd.h> | ||
| 82 | # undef pselect | ||
| 83 | |||
| 84 | int | ||
| 85 | rpl_pselect (int nfds, fd_set *restrict rfds, | ||
| 86 | fd_set *restrict wfds, fd_set *restrict xfds, | ||
| 87 | struct timespec const *restrict timeout, | ||
| 88 | sigset_t const *restrict sigmask) | ||
| 89 | { | ||
| 90 | int i; | ||
| 91 | |||
| 92 | /* FreeBSD 8.2 has a bug: it does not always detect invalid fds. */ | ||
| 93 | if (nfds < 0 || nfds > FD_SETSIZE) | ||
| 94 | { | ||
| 95 | errno = EINVAL; | ||
| 96 | return -1; | ||
| 97 | } | ||
| 98 | for (i = 0; i < nfds; i++) | ||
| 99 | { | ||
| 100 | if (((rfds && FD_ISSET (i, rfds)) | ||
| 101 | || (wfds && FD_ISSET (i, wfds)) | ||
| 102 | || (xfds && FD_ISSET (i, xfds))) | ||
| 103 | && dup2 (i, i) != i) | ||
| 104 | return -1; | ||
| 105 | } | ||
| 106 | |||
| 107 | return pselect (nfds, rfds, wfds, xfds, timeout, sigmask); | ||
| 108 | } | ||
| 109 | |||
| 110 | #endif | ||