#ifndef _FD_SET
#define _FD_SET
#include <machine/types.h>
#if !KERNEL
#include <Availability.h>
#endif
#ifdef FD_SETSIZE
#define __DARWIN_FD_SETSIZE FD_SETSIZE
#else
#define __DARWIN_FD_SETSIZE 1024
#endif
#define __DARWIN_NBBY 8
#define __DARWIN_NFDBITS (sizeof(__int32_t) * __DARWIN_NBBY)
#define __DARWIN_howmany(x, y) ((((x) % (y)) == 0) ? ((x) / (y)) : (((x) / (y)) + 1))
__BEGIN_DECLS
typedef struct fd_set {
__int32_t fds_bits[__DARWIN_howmany(__DARWIN_FD_SETSIZE, __DARWIN_NFDBITS)];
} fd_set;
#if !KERNEL
int __darwin_check_fd_set_overflow(int, const void *, int) __API_AVAILABLE(macosx(10.16), ios(14.0), tvos(14.0), watchos(7.0));
#endif
__END_DECLS
#if !KERNEL
__header_always_inline int
__darwin_check_fd_set(int _a, const void *_b)
{
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
#endif
if ((uintptr_t)&__darwin_check_fd_set_overflow != (uintptr_t) 0) {
#if defined(_DARWIN_UNLIMITED_SELECT) || defined(_DARWIN_C_SOURCE)
return __darwin_check_fd_set_overflow(_a, _b, 1);
#else
return __darwin_check_fd_set_overflow(_a, _b, 0);
#endif
} else {
return 1;
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif
}
__header_always_inline int
__darwin_fd_isset(int _fd, const struct fd_set *_p)
{
if (__darwin_check_fd_set(_fd, (const void *) _p)) {
return _p->fds_bits[(unsigned long)_fd / __DARWIN_NFDBITS] & ((__int32_t)(((unsigned long)1) << ((unsigned long)_fd % __DARWIN_NFDBITS)));
}
return 0;
}
__header_always_inline void
__darwin_fd_set(int _fd, struct fd_set *const _p)
{
if (__darwin_check_fd_set(_fd, (const void *) _p)) {
(_p->fds_bits[(unsigned long)_fd / __DARWIN_NFDBITS] |= ((__int32_t)(((unsigned long)1) << ((unsigned long)_fd % __DARWIN_NFDBITS))));
}
}
__header_always_inline void
__darwin_fd_clr(int _fd, struct fd_set *const _p)
{
if (__darwin_check_fd_set(_fd, (const void *) _p)) {
(_p->fds_bits[(unsigned long)_fd / __DARWIN_NFDBITS] &= ~((__int32_t)(((unsigned long)1) << ((unsigned long)_fd % __DARWIN_NFDBITS))));
}
}
#else
__header_always_inline int
__darwin_fd_isset(int _fd, const struct fd_set *_p)
{
return _p->fds_bits[(unsigned long)_fd / __DARWIN_NFDBITS] & ((__int32_t)(((unsigned long)1) << ((unsigned long)_fd % __DARWIN_NFDBITS)));
}
__header_always_inline void
__darwin_fd_set(int _fd, struct fd_set *const _p)
{
(_p->fds_bits[(unsigned long)_fd / __DARWIN_NFDBITS] |= ((__int32_t)(((unsigned long)1) << ((unsigned long)_fd % __DARWIN_NFDBITS))));
}
__header_always_inline void
__darwin_fd_clr(int _fd, struct fd_set *const _p)
{
(_p->fds_bits[(unsigned long)_fd / __DARWIN_NFDBITS] &= ~((__int32_t)(((unsigned long)1) << ((unsigned long)_fd % __DARWIN_NFDBITS))));
}
#endif
#define __DARWIN_FD_SET(n, p) __darwin_fd_set((n), (p))
#define __DARWIN_FD_CLR(n, p) __darwin_fd_clr((n), (p))
#define __DARWIN_FD_ISSET(n, p) __darwin_fd_isset((n), (p))
#if __GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 3
#define __DARWIN_FD_ZERO(p) __builtin_bzero(p, sizeof(*(p)))
#else
#define __DARWIN_FD_ZERO(p) bzero(p, sizeof(*(p)))
#endif
#define __DARWIN_FD_COPY(f, t) bcopy(f, t, sizeof(*(f)))
#endif