1 #ifndef __wasilibc___fd_set_h
2 #define __wasilibc___fd_set_h
3
4 #include <__typedef_fd_set.h>
5
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9
FD_CLR(int __fd,fd_set * __set)10 static __inline void FD_CLR(int __fd, fd_set *__set) {
11 size_t __n = __set->__nfds;
12 for (int *__p = __set->__fds, *__e = __p + __n;
13 __p < __e; ++__p)
14 {
15 if (*__p == __fd) {
16 *__p = __e[-1];
17 __set->__nfds = __n - 1;
18 return;
19 }
20 }
21 }
22
23 static __inline
24 #ifdef __cplusplus
25 bool
26 #else
27 _Bool
28 #endif
FD_ISSET(int __fd,const fd_set * __set)29 FD_ISSET(int __fd, const fd_set *__set)
30 {
31 size_t __n = __set->__nfds;
32 for (const int *__p = __set->__fds, *__e = __p + __n;
33 __p < __e; ++__p)
34 {
35 if (*__p == __fd) {
36 return 1;
37 }
38 }
39 return 0;
40 }
41
FD_SET(int __fd,fd_set * __set)42 static __inline void FD_SET(int __fd, fd_set *__set) {
43 size_t __n = __set->__nfds;
44 for (const int *__p = __set->__fds, *__e = __p + __n;
45 __p < __e; ++__p)
46 {
47 if (*__p == __fd) {
48 return;
49 }
50 }
51 __set->__nfds = __n + 1;
52 __set->__fds[__n] = __fd;
53 }
54
FD_ZERO(fd_set * __set)55 static __inline void FD_ZERO(fd_set *__set) {
56 __set->__nfds = 0;
57 }
58
FD_COPY(const fd_set * __restrict __from,fd_set * __restrict __to)59 static __inline void FD_COPY(const fd_set *__restrict __from,
60 fd_set *__restrict __to) {
61 size_t __n = __from->__nfds;
62 __to->__nfds = __n;
63 __builtin_memcpy(__to->__fds, __from->__fds, __n * sizeof(int));
64 }
65
66 #define FD_CLR(fd, set) (FD_CLR((fd), (set)))
67 #define FD_ISSET(fd, set) (FD_ISSET((fd), (set)))
68 #define FD_SET(fd, set) (FD_SET((fd), (set)))
69 #define FD_ZERO(set) (FD_ZERO((set)))
70 #define FD_COPY(from, to) (FD_COPY((from), (to)))
71
72 #ifdef __cplusplus
73 }
74 #endif
75
76 #endif
77