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 (nfds < 0 || nfds > FD_SETSIZE)
49 {
50 errno = EINVAL;
51 return -1;
52 }
53
54 if (timeout)
55 {
56 if (! (0 <= timeout->tv_nsec && timeout->tv_nsec < 1000000000))
57 {
58 errno = EINVAL;
59 return -1;
60 }
61
62 tv = (struct timeval) {
63 .tv_sec = timeout->tv_sec,
64 .tv_usec = (timeout->tv_nsec + 999) / 1000
65 };
66 tvp = &tv;
67 }
68 else
69 tvp = NULL;
70
71
72
73 if (sigmask)
74 pthread_sigmask (SIG_SETMASK, sigmask, &origmask);
75
76 select_result = select (nfds, rfds, wfds, xfds, tvp);
77
78 if (sigmask)
79 {
80 int select_errno = errno;
81 pthread_sigmask (SIG_SETMASK, &origmask, NULL);
82 errno = select_errno;
83 }
84
85 return select_result;
86 }
87
88 #else
89 # include <unistd.h>
90 # undef pselect
91
92 int
93 rpl_pselect (int nfds, fd_set *restrict rfds,
94 fd_set *restrict wfds, fd_set *restrict xfds,
95 struct timespec const *restrict timeout,
96 sigset_t const *restrict sigmask)
97 {
98 int i;
99
100
101 if (nfds < 0 || nfds > FD_SETSIZE)
102 {
103 errno = EINVAL;
104 return -1;
105 }
106 for (i = 0; i < nfds; i++)
107 {
108 if (((rfds && FD_ISSET (i, rfds))
109 || (wfds && FD_ISSET (i, wfds))
110 || (xfds && FD_ISSET (i, xfds)))
111 && dup2 (i, i) != i)
112 return -1;
113 }
114
115 return pselect (nfds, rfds, wfds, xfds, timeout, sigmask);
116 }
117
118 #endif