]> git.proxmox.com Git - wasi-libc.git/commitdiff
Implement FD_SET, FD_CLR, etc.
authorDan Gohman <sunfish@mozilla.com>
Sat, 20 Apr 2019 00:22:28 +0000 (17:22 -0700)
committerDan Gohman <sunfish@mozilla.com>
Tue, 23 Apr 2019 22:01:23 +0000 (15:01 -0700)
Previously, FD_SET and friends were missing their actual definitions.
This provides definitions, entirely within the system headers in a
way that doesn't need instantiated out-of-line definitions.

expected/wasm32-wasi/defined-symbols.txt
expected/wasm32-wasi/predefined-macros.txt
libc-bottom-half/cloudlibc/src/libc/sys/select/FD_CLR.c [deleted file]
libc-bottom-half/cloudlibc/src/libc/sys/select/FD_COPY.c [deleted file]
libc-bottom-half/cloudlibc/src/libc/sys/select/FD_ISSET.c [deleted file]
libc-bottom-half/cloudlibc/src/libc/sys/select/FD_SET.c [deleted file]
libc-bottom-half/cloudlibc/src/libc/sys/select/FD_ZERO.c [deleted file]
libc-bottom-half/headers/public/__fd_set.h

index 63a413e418046b084115f447b054ff25721e7418..c974a13c00d0ea0e4bfcb423ac2b8b28501df5e0 100644 (file)
@@ -1,8 +1,3 @@
-FD_CLR
-FD_COPY
-FD_ISSET
-FD_SET
-FD_ZERO
 _CLOCK_MONOTONIC
 _CLOCK_PROCESS_CPUTIME_ID
 _CLOCK_REALTIME
index 3500ce1f9aee5d0b85b142834e9515f11287f20a..59e83c5ffbae4b0c377ac4d6c7e08bf55d717a78 100644 (file)
 #define EX__BASE 64
 #define EX__MAX 78
 #define FD_CLOEXEC (1)
-#define FD_CLR(fd,set) FD_CLR((fd), (set))
-#define FD_COPY(from,to) FD_COPY(from, to)
-#define FD_ISSET(fd,set) FD_ISSET((fd), (set))
-#define FD_SET(fd,set) FD_SET((fd), (set))
+#define FD_CLR(fd,set) (FD_CLR((fd), (set)))
+#define FD_COPY(from,to) (FD_COPY((from), (to)))
+#define FD_ISSET(fd,set) (FD_ISSET((fd), (set)))
+#define FD_SET(fd,set) (FD_SET((fd), (set)))
 #define FD_SETSIZE 1024
-#define FD_ZERO(set) FD_ZERO((set))
+#define FD_ZERO(set) (FD_ZERO((set)))
 #define FE_ALL_EXCEPT 0
 #define FE_DFL_ENV ((const fenv_t *) -1)
 #define FE_TONEAREST 0
diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/select/FD_CLR.c b/libc-bottom-half/cloudlibc/src/libc/sys/select/FD_CLR.c
deleted file mode 100644 (file)
index a8010ae..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright (c) 2015 Nuxi, https://nuxi.nl/
-//
-// SPDX-License-Identifier: BSD-2-Clause
-
-#include <sys/select.h>
-
-#ifndef FD_CLR
-#error "FD_CLR is supposed to be a macro as well"
-#endif
-
-// clang-format off
-void (FD_CLR)(int fd, fd_set *fd_set) {
-  FD_CLR(fd, fd_set);
-}
diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/select/FD_COPY.c b/libc-bottom-half/cloudlibc/src/libc/sys/select/FD_COPY.c
deleted file mode 100644 (file)
index d3b83a2..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright (c) 2015 Nuxi, https://nuxi.nl/
-//
-// SPDX-License-Identifier: BSD-2-Clause
-
-#include <sys/select.h>
-
-#ifndef FD_COPY
-#error "FD_COPY is supposed to be a macro as well"
-#endif
-
-// clang-format off
-void (FD_COPY)(const fd_set *restrict from, fd_set *restrict to) {
-  FD_COPY(from, to);
-}
diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/select/FD_ISSET.c b/libc-bottom-half/cloudlibc/src/libc/sys/select/FD_ISSET.c
deleted file mode 100644 (file)
index 952468e..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright (c) 2015 Nuxi, https://nuxi.nl/
-//
-// SPDX-License-Identifier: BSD-2-Clause
-
-#include <sys/select.h>
-
-#ifndef FD_ISSET
-#error "FD_ISSET is supposed to be a macro as well"
-#endif
-
-// clang-format off
-int (FD_ISSET)(int fd, const fd_set *fd_set) {
-  return FD_ISSET(fd, fd_set);
-}
diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/select/FD_SET.c b/libc-bottom-half/cloudlibc/src/libc/sys/select/FD_SET.c
deleted file mode 100644 (file)
index 647994a..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright (c) 2015 Nuxi, https://nuxi.nl/
-//
-// SPDX-License-Identifier: BSD-2-Clause
-
-#include <sys/select.h>
-
-#ifndef FD_SET
-#error "FD_SET is supposed to be a macro as well"
-#endif
-
-// clang-format off
-void (FD_SET)(int fd, fd_set *fd_set) {
-  FD_SET(fd, fd_set);
-}
diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/select/FD_ZERO.c b/libc-bottom-half/cloudlibc/src/libc/sys/select/FD_ZERO.c
deleted file mode 100644 (file)
index 66d3d88..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright (c) 2015 Nuxi, https://nuxi.nl/
-//
-// SPDX-License-Identifier: BSD-2-Clause
-
-#include <sys/select.h>
-
-#ifndef FD_ZERO
-#error "FD_ZERO is supposed to be a macro as well"
-#endif
-
-// clang-format off
-void (FD_ZERO)(fd_set *fd_set) {
-  FD_ZERO(fd_set);
-}
index 0fc2aa2a8c486bd22393533687726e79feff76f4..7be0b9fcea0411d5cc6a838ba4860b058aa4fb87 100644 (file)
@@ -7,17 +7,67 @@
 extern "C" {
 #endif
 
-void FD_CLR(int, fd_set *);
-int FD_ISSET(int, const fd_set *);
-void FD_SET(int, fd_set *);
-void FD_ZERO(fd_set *);
-void FD_COPY(const fd_set *, fd_set *);
-
-#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)
+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
 }