1 /*
2  * Copyright (C) 2015-2017 Alibaba Group Holding Limited
3  */
4 
5 #ifndef _SYS_SELECT_H__
6 #define _SYS_SELECT_H__
7 
8 #ifndef	FD_SETSIZE
9 #define	FD_SETSIZE	256
10 #endif
11 
12 #define	NBBY	8		/* number of bits in a byte */
13 
14 typedef	long	fd_mask;
15 #define	NFDBITS	(sizeof (fd_mask) * NBBY)	/* bits per mask */
16 #ifndef	howmany
17 #define	howmany(x,y)	(((x)+((y)-1))/(y))
18 #endif
19 
20 /* We use a macro for fd_set so that including Sockets.h afterwards
21    can work.  */
22 typedef	struct _types_fd_set {
23 	fd_mask	fds_bits[howmany(FD_SETSIZE, NFDBITS)];
24 } _types_fd_set;
25 
26 #define fd_set _types_fd_set
27 
28 #define	FD_SET(n, p)	((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS)))
29 #define	FD_CLR(n, p)	((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS)))
30 #define	FD_ISSET(n, p)	((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS)))
31 #define FD_ZERO(p)      memset((void*)(p), 0, sizeof(*(p)))
32 
33 #endif
34