From a205a40bccdd2fadcf29809659f7bda88e8ef785 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Fri, 20 Feb 2026 19:58:28 +0100 Subject: [PATCH] p3: implement fcntl Signed-off-by: Roman Volosatovs --- libc-bottom-half/cloudlibc/src/libc/fcntl/fcntl.c | 14 +++----------- libc-bottom-half/cloudlibc/src/libc/poll/poll.c | 1 - .../cloudlibc/src/libc/sys/ioctl/ioctl.c | 6 +----- libc-bottom-half/sources/udp.c | 4 ++-- test/CMakeLists.txt | 2 +- 5 files changed, 7 insertions(+), 20 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/fcntl/fcntl.c b/libc-bottom-half/cloudlibc/src/libc/fcntl/fcntl.c index 55ce46bbd..da9051a88 100644 --- a/libc-bottom-half/cloudlibc/src/libc/fcntl/fcntl.c +++ b/libc-bottom-half/cloudlibc/src/libc/fcntl/fcntl.c @@ -13,7 +13,7 @@ #endif int fcntl(int fildes, int cmd, ...) { -#ifdef __wasip2__ +#if defined(__wasip2__) || defined(__wasip3__) descriptor_table_entry_t *entry = descriptor_table_get_ref(fildes); if (entry == NULL) return -1; @@ -51,16 +51,12 @@ int fcntl(int fildes, int cmd, ...) { oflags |= O_SEARCH; } return oflags; -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) if (!entry->vtable->fcntl_getfl) { errno = EINVAL; return -1; } return entry->vtable->fcntl_getfl(entry->data); -#elif defined(__wasip3__) - // TODO(wasip3) - errno = ENOTSUP; - return -1; #else # error "Unknown WASI version" #endif @@ -80,16 +76,12 @@ int fcntl(int fildes, int cmd, ...) { errno = error; return -1; } -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) if (!entry->vtable->fcntl_setfl) { errno = EINVAL; return -1; } return entry->vtable->fcntl_setfl(entry->data, flags); -#elif defined(__wasip3__) - // TODO(wasip3) - errno = ENOTSUP; - return -1; #else # error "Unknown WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/poll/poll.c b/libc-bottom-half/cloudlibc/src/libc/poll/poll.c index 22567edb6..93886c3fc 100644 --- a/libc-bottom-half/cloudlibc/src/libc/poll/poll.c +++ b/libc-bottom-half/cloudlibc/src/libc/poll/poll.c @@ -288,7 +288,6 @@ static int poll_impl(struct pollfd *fds, size_t nfds, int timeout) { #elif defined(__wasip3__) static int poll_impl(struct pollfd *fds, size_t nfds, int timeout) { - // TODO(wasip3) errno = ENOTSUP; return -1; } 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 7b78d3224..bc360249e 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c @@ -89,7 +89,7 @@ int ioctl(int fildes, int request, ...) { return -1; } return 0; -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) descriptor_table_entry_t *entry = descriptor_table_get_ref(fildes); va_list ap; va_start(ap, request); @@ -101,10 +101,6 @@ int ioctl(int fildes, int request, ...) { return -1; } return entry->vtable->set_blocking(entry->data, blocking); -#elif defined(__wasip3__) - // TODO(wasip3) - errno = ENOTSUP; - return -1; #else # error "Unknown WASI version" #endif diff --git a/libc-bottom-half/sources/udp.c b/libc-bottom-half/sources/udp.c index 7b958633b..6c585bd7f 100644 --- a/libc-bottom-half/sources/udp.c +++ b/libc-bottom-half/sources/udp.c @@ -836,6 +836,7 @@ static int udp_poll_register(void *data, poll_state_t *state, short events) { } return 0; } +#endif static int udp_fcntl_getfl(void *data) { udp_socket_t *socket = (udp_socket_t *)data; @@ -855,7 +856,6 @@ static int udp_fcntl_setfl(void *data, int flags) { } return 0; } -#endif static descriptor_vtable_t udp_vtable = { .free = udp_free, @@ -874,8 +874,8 @@ static descriptor_vtable_t udp_vtable = { .setsockopt = udp_setsockopt, .poll_register = udp_poll_register, +#endif .fcntl_getfl = udp_fcntl_getfl, .fcntl_setfl = udp_fcntl_setfl, -#endif }; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index bb51b2c05..33ca27e3d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -317,7 +317,7 @@ if (NOT (WASI STREQUAL "p1")) add_wasilibc_test(sockets-nonblocking-udp.c NETWORK FAILP3) add_wasilibc_test(sockets-nonblocking-multiple.c NETWORK FAILP3) add_wasilibc_test(sockets-nonblocking-udp-multiple.c NETWORK FAILP3) - add_wasilibc_test(sockets-fcntl.c NETWORK FAILP3) + add_wasilibc_test(sockets-fcntl.c NETWORK) # TODO: flaky tests # add_wasilibc_test(sockets-nonblocking.c NETWORK)