summaryrefslogtreecommitdiffstats
path: root/libc-bottom-half/headers/public/__fd_set.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 13:54:38 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 13:54:38 +0000
commit8c1ab65c0f548d20b7f177bdb736daaf603340e1 (patch)
treedf55b7e75bf43f2bf500845b105afe3ac3a5157e /libc-bottom-half/headers/public/__fd_set.h
parentInitial commit. (diff)
downloadwasi-libc-8c1ab65c0f548d20b7f177bdb736daaf603340e1.tar.xz
wasi-libc-8c1ab65c0f548d20b7f177bdb736daaf603340e1.zip
Adding upstream version 0.0~git20221206.8b7148f.upstream/0.0_git20221206.8b7148f
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libc-bottom-half/headers/public/__fd_set.h')
-rw-r--r--libc-bottom-half/headers/public/__fd_set.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/libc-bottom-half/headers/public/__fd_set.h b/libc-bottom-half/headers/public/__fd_set.h
new file mode 100644
index 0000000..7be0b9f
--- /dev/null
+++ b/libc-bottom-half/headers/public/__fd_set.h
@@ -0,0 +1,76 @@
+#ifndef __wasilibc___fd_set_h
+#define __wasilibc___fd_set_h
+
+#include <__typedef_fd_set.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static __inline void FD_CLR(int __fd, fd_set *__set) {
+ size_t __n = __set->__nfds;
+ for (int *__p = __set->__fds, *__e = __p + __n;
+ __p < __e; ++__p)
+ {
+ if (*__p == __fd) {
+ *__p = __e[-1];
+ __set->__nfds = __n - 1;
+ return;
+ }
+ }
+}
+
+static __inline
+#ifdef __cplusplus
+bool
+#else
+_Bool
+#endif
+FD_ISSET(int __fd, const fd_set *__set)
+{
+ size_t __n = __set->__nfds;
+ for (const int *__p = __set->__fds, *__e = __p + __n;
+ __p < __e; ++__p)
+ {
+ if (*__p == __fd) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+static __inline void FD_SET(int __fd, fd_set *__set) {
+ size_t __n = __set->__nfds;
+ for (const int *__p = __set->__fds, *__e = __p + __n;
+ __p < __e; ++__p)
+ {
+ if (*__p == __fd) {
+ return;
+ }
+ }
+ __set->__nfds = __n + 1;
+ __set->__fds[__n] = __fd;
+}
+
+static __inline void FD_ZERO(fd_set *__set) {
+ __set->__nfds = 0;
+}
+
+static __inline void FD_COPY(const fd_set *__restrict __from,
+ fd_set *__restrict __to) {
+ size_t __n = __from->__nfds;
+ __to->__nfds = __n;
+ __builtin_memcpy(__to->__fds, __from->__fds, __n * sizeof(int));
+}
+
+#define FD_CLR(fd, set) (FD_CLR((fd), (set)))
+#define FD_ISSET(fd, set) (FD_ISSET((fd), (set)))
+#define FD_SET(fd, set) (FD_SET((fd), (set)))
+#define FD_ZERO(set) (FD_ZERO((set)))
+#define FD_COPY(from, to) (FD_COPY((from), (to)))
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif