@@ -44,14 +44,17 @@ __BEGIN_DECLS
4444typedef unsigned long fd_mask ;
4545
4646/**
47- * The limit on the largest fd that can be used with this API .
47+ * The limit on the largest fd that can be used with fd_set .
4848 * Use <poll.h> instead.
4949 */
5050#define FD_SETSIZE 1024
5151#define NFDBITS (8 * sizeof(fd_mask))
5252
5353/**
5454 * The type of a file descriptor set. Limited to 1024 fds.
55+ * The underlying system calls do not have this limit,
56+ * and callers can allocate their own sets with calloc().
57+ *
5558 * Use <poll.h> instead.
5659 */
5760typedef struct {
@@ -60,30 +63,27 @@ typedef struct {
6063
6164#define __FDELT (fd ) ((fd) / NFDBITS)
6265#define __FDMASK (fd ) (1UL << ((fd) % NFDBITS))
63- #define __FDS_BITS (type ,set ) (__BIONIC_CAST(static_cast, type, set)->fds_bits)
64-
65- /* Inline loop so we don't have to declare memset. */
66- #define FD_ZERO (set ) \
67- do { \
68- size_t __i; \
69- for (__i = 0; __i < sizeof(fd_set)/sizeof(fd_mask); ++__i) { \
70- (set)->fds_bits[__i] = 0; \
71- } \
72- } while (0)
66+ #define __FDS_BITS (type , set ) (__BIONIC_CAST(static_cast, type, set)->fds_bits)
7367
7468void __FD_CLR_chk (int , fd_set * _Nonnull , size_t );
7569void __FD_SET_chk (int , fd_set * _Nonnull, size_t );
7670int __FD_ISSET_chk (int , const fd_set * _Nonnull, size_t );
7771
78- #define __FD_CLR (fd , set ) (__FDS_BITS(fd_set*,set)[__FDELT(fd)] &= ~__FDMASK(fd))
79- #define __FD_SET (fd , set ) (__FDS_BITS(fd_set*,set)[__FDELT(fd)] |= __FDMASK(fd))
80- #define __FD_ISSET (fd , set ) ((__FDS_BITS(const fd_set*,set)[__FDELT(fd)] & __FDMASK(fd)) != 0)
72+ /** FD_CLR() with no bounds checking for users that allocated their own set. */
73+ #define __FD_CLR (fd , set ) (__FDS_BITS(fd_set*, set)[__FDELT(fd)] &= ~__FDMASK(fd))
74+ /** FD_SET() with no bounds checking for users that allocated their own set. */
75+ #define __FD_SET (fd , set ) (__FDS_BITS(fd_set*, set)[__FDELT(fd)] |= __FDMASK(fd))
76+ /** FD_ISSET() with no bounds checking for users that allocated their own set. */
77+ #define __FD_ISSET (fd , set ) ((__FDS_BITS(const fd_set*, set)[__FDELT(fd)] & __FDMASK(fd)) != 0)
78+
79+ /** Removes all 1024 fds from the given set. Use <poll.h> instead. */
80+ #define FD_ZERO (set ) __builtin_memset(set, 0, sizeof(*__BIONIC_CAST(static_cast, const fd_set*, set)))
8181
82- /** Removes `fd` from the given set. Use <poll.h> instead. */
82+ /** Removes `fd` from the given set. Limited to fds under 1024. Use <poll.h> instead. */
8383#define FD_CLR (fd , set ) __FD_CLR_chk(fd, set, __bos(set))
84- /** Adds `fd` to the given set. Use <poll.h> instead. */
84+ /** Adds `fd` to the given set. Limited to fds under 1024. Use <poll.h> instead. */
8585#define FD_SET (fd , set ) __FD_SET_chk(fd, set, __bos(set))
86- /** Tests whether `fd` is in the given set. Use <poll.h> instead. */
86+ /** Tests whether `fd` is in the given set. Limited to fds under 1024. Use <poll.h> instead. */
8787#define FD_ISSET (fd , set ) __FD_ISSET_chk(fd, set, __bos(set))
8888
8989/**
0 commit comments