This source file includes following definitions.
- pselect
- rpl_pselect
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 #include <config.h>
23
24 #include <sys/select.h>
25
26 #include <errno.h>
27 #include <signal.h>
28
29
30
31
32
33
34
35
36 #if !HAVE_PSELECT
37
38 int
39 pselect (int nfds, fd_set *restrict rfds,
40 fd_set *restrict wfds, fd_set *restrict xfds,
41 struct timespec const *restrict timeout,
42 sigset_t const *restrict sigmask)
43 {
44 int select_result;
45 sigset_t origmask;
46 struct timeval tv, *tvp;
47
48 if (timeout)
49 {
50 if (! (0 <= timeout->tv_nsec && timeout->tv_nsec < 1000000000))
51 {
52 errno = EINVAL;
53 return -1;
54 }
55
56 tv.tv_sec = timeout->tv_sec;
57 tv.tv_usec = (timeout->tv_nsec + 999) / 1000;
58 tvp = &tv;
59 }
60 else
61 tvp = NULL;
62
63
64
65 if (sigmask)
66 pthread_sigmask (SIG_SETMASK, sigmask, &origmask);
67
68 select_result = select (nfds, rfds, wfds, xfds, tvp);
69
70 if (sigmask)
71 {
72 int select_errno = errno;
73 pthread_sigmask (SIG_SETMASK, &origmask, NULL);
74 errno = select_errno;
75 }
76
77 return select_result;
78 }
79
80 #else
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
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