summaryrefslogtreecommitdiffstats
path: root/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-26 16:08:04 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-26 16:08:04 +0000
commit41927c28dd5030318be5cf71f515449d55b2802b (patch)
tree41f7cef3a417fee1ee171cdb4f2709f4372ae4f3 /libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c
parentReleasing progress-linux version 0.0~git20230821.ec4566b-2~progress7.99u1. (diff)
downloadwasi-libc-41927c28dd5030318be5cf71f515449d55b2802b.tar.xz
wasi-libc-41927c28dd5030318be5cf71f515449d55b2802b.zip
Merging upstream version 0.0~git20240411.9e8c542.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c')
-rw-r--r--libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c57
1 files changed, 56 insertions, 1 deletions
diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c b/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c
index 7d03cc6..2c968b2 100644
--- a/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c
+++ b/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c
@@ -4,11 +4,66 @@
#include <sys/ioctl.h>
-#include <wasi/api.h>
#include <errno.h>
#include <stdarg.h>
+#include <wasi/api.h>
+#ifdef __wasilibc_use_wasip2
+#include <wasi/descriptor_table.h>
+#endif
+
int ioctl(int fildes, int request, ...) {
+#ifdef __wasilibc_use_wasip2
+ descriptor_table_entry_t *entry;
+ if (descriptor_table_get_ref(fildes, &entry)) {
+ switch (entry->tag) {
+ case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: {
+ tcp_socket_t *socket = &entry->tcp_socket;
+ switch (request) {
+ case FIONBIO: {
+ va_list ap;
+ va_start(ap, request);
+ socket->blocking = *va_arg(ap, const int *) ==
+ 0;
+ va_end(ap);
+
+ return 0;
+ }
+
+ default:
+ // TODO wasi-sockets: anything else we should support?
+ errno = EINVAL;
+ return -1;
+ }
+ }
+
+ case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: {
+ udp_socket_t *socket = &entry->udp_socket;
+ switch (request) {
+ case FIONBIO: {
+ va_list ap;
+ va_start(ap, request);
+ socket->blocking = *va_arg(ap, const int *) ==
+ 0;
+ va_end(ap);
+
+ return 0;
+ }
+
+ default:
+ // TODO wasi-sockets: anything else we should support?
+ errno = EINVAL;
+ return -1;
+ }
+ }
+
+ default:
+ errno = ENOPROTOOPT;
+ return -1;
+ }
+ }
+#endif // __wasilibc_use_wasip2
+
switch (request) {
case FIONREAD: {
// Poll the file descriptor to determine how many bytes can be read.