xref: /haiku/headers/posix/sys/select.h (revision 2ae568931fcac7deb9f1e6ff4e47213fbfe4029b)
1 #ifndef _SYS_SELECT_H
2 #define _SYS_SELECT_H
3 /*
4 ** Distributed under the terms of the OpenBeOS License.
5 */
6 
7 
8 #include <sys/time.h>
9 #include <signal.h>
10 
11 
12 /* If FD_SET is already defined, only the select() prototype is
13  * exported in this header.
14  */
15 #ifndef FD_SET
16 
17 /* You can define your own FDSETSIZE if you need more bits - but
18  * it should be enough for most uses.
19  */
20 #ifndef FD_SETSIZE
21 #	define FD_SETSIZE 1024
22 #endif
23 
24 typedef unsigned long fd_mask;
25 
26 #ifndef _howmany
27 #	define _howmany(x, y) (((x) + ((y) - 1)) / (y))
28 #endif
29 
30 #define NFDBITS (sizeof(fd_mask) * 8)	/* bits per mask */
31 
32 typedef struct fd_set {
33 	fd_mask bits[_howmany(FD_SETSIZE, NFDBITS)];
34 } fd_set;
35 
36 #define _FD_BITSINDEX(fd) ((fd) / NFDBITS)
37 #define _FD_BIT(fd) (1L << ((fd) % NFDBITS))
38 
39 #define FD_ZERO(set) memset((set), 0, sizeof(fd_set))
40 #define FD_SET(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] |= _FD_BIT(fd))
41 #define FD_CLR(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] &= ~_FD_BIT(fd))
42 #define FD_ISSET(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] & _FD_BIT(fd))
43 
44 #endif	/* FD_SET */
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 extern int pselect(int numBits, struct fd_set *readBits, struct fd_set *writeBits,
51 			struct fd_set *errorBits, const struct timespec *timeout, const sigset_t *sigMask);
52 extern int select(int numBits, struct fd_set *readBits, struct fd_set *writeBits,
53 			struct fd_set *errorBits, struct timeval *timeout);
54 
55 #ifdef __cplusplus
56 }
57 #endif
58 
59 #endif	/* _SYS_SELECT_H */
60