1 //===-- Macros defined in sys/select.h header file ------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef __LLVM_LIBC_MACROS_SYS_SELECT_MACROS_H
10 #define __LLVM_LIBC_MACROS_SYS_SELECT_MACROS_H
12 #define FD_SETSIZE 1024
13 #define __FD_SET_WORD_TYPE unsigned long
14 #define __FD_SET_WORD_SIZE (sizeof(__FD_SET_WORD_TYPE) * 8)
15 #define __FD_SET_ARRAYSIZE (FD_SETSIZE / __FD_SET_WORD_SIZE)
17 #define FD_ZERO(set) \
20 for (i = 0; i < __FD_SET_ARRAYSIZE; ++i) \
21 (set)->__set[i] = 0; \
24 #define __FD_WORD(fd) ((fd) / __FD_SET_WORD_SIZE)
25 #define __FD_MASK(fd) \
26 ((__FD_SET_WORD_TYPE)1) << ((__FD_SET_WORD_TYPE)((fd) % __FD_SET_WORD_SIZE))
28 #define FD_CLR(fd, set) (void)((set)->__set[__FD_WORD(fd)] &= ~__FD_MASK(fd))
30 #define FD_SET(fd, set) (void)((set)->__set[__FD_WORD(fd)] |= __FD_MASK(fd))
32 #define FD_ISSET(fd, set) \
33 (int)(((set)->__set[__FD_WORD(fd)] & __FD_MASK(fd)) != 0)
35 #endif // __LLVM_LIBC_MACROS_SYS_SELECT_MACROS_H