xref: /nrf52832-nimble/rt-thread/include/libc/libc_fdset.h (revision 104654410c56c573564690304ae786df310c91fc)
1 /*
2  * Copyright (c) 2006-2018, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /*
8  * File      : libc_errno.h
9  *
10  * Change Logs:
11  * Date           Author       Notes
12  * 2017-10-30     Bernard      The first version
13  */
14 
15 #ifndef LIBC_FDSET_H__
16 #define LIBC_FDSET_H__
17 
18 #include <rtconfig.h>
19 
20 #if defined(RT_USING_NEWLIB) || defined(_WIN32)
21 #include <sys/types.h>
22 #if defined(HAVE_SYS_SELECT_H)
23 #include <sys/select.h>
24 #endif
25 
26 #else
27 
28 #ifdef SAL_USING_POSIX
29 
30 #ifdef FD_SETSIZE
31 #undef FD_SETSIZE
32 #endif
33 
34 #define FD_SETSIZE      DFS_FD_MAX
35 #endif
36 
37 #  ifndef   FD_SETSIZE
38 #   define  FD_SETSIZE  32
39 #  endif
40 
41 #  define   NBBY    8       /* number of bits in a byte */
42 
43 typedef long    fd_mask;
44 #  define   NFDBITS (sizeof (fd_mask) * NBBY)   /* bits per mask */
45 #  ifndef   howmany
46 #   define  howmany(x,y)    (((x)+((y)-1))/(y))
47 #  endif
48 
49 /* We use a macro for fd_set so that including Sockets.h afterwards
50    can work.  */
51 typedef struct _types_fd_set {
52     fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
53 } _types_fd_set;
54 
55 #define fd_set _types_fd_set
56 
57 #  define   FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS)))
58 #  define   FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS)))
59 #  define   FD_ISSET(n, p)  ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS)))
60 #  define   FD_ZERO(p)      memset((void*)(p), 0, sizeof(*(p)))
61 
62 #endif
63 
64 #endif
65