Skip to content

Commit ab1d04b

Browse files
p3: implement fcntl (WebAssembly#752)
Rebasing of WebAssembly#745 after recent merges Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net> Co-authored-by: Roman Volosatovs <rvolosatovs@riseup.net>
1 parent bc269eb commit ab1d04b

5 files changed

Lines changed: 7 additions & 20 deletions

File tree

libc-bottom-half/cloudlibc/src/libc/fcntl/fcntl.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#endif
1414

1515
int fcntl(int fildes, int cmd, ...) {
16-
#ifdef __wasip2__
16+
#if defined(__wasip2__) || defined(__wasip3__)
1717
descriptor_table_entry_t *entry = descriptor_table_get_ref(fildes);
1818
if (entry == NULL)
1919
return -1;
@@ -51,16 +51,12 @@ int fcntl(int fildes, int cmd, ...) {
5151
oflags |= O_SEARCH;
5252
}
5353
return oflags;
54-
#elif defined(__wasip2__)
54+
#elif defined(__wasip2__) || defined(__wasip3__)
5555
if (!entry->vtable->fcntl_getfl) {
5656
errno = EINVAL;
5757
return -1;
5858
}
5959
return entry->vtable->fcntl_getfl(entry->data);
60-
#elif defined(__wasip3__)
61-
// TODO(wasip3)
62-
errno = ENOTSUP;
63-
return -1;
6460
#else
6561
# error "Unknown WASI version"
6662
#endif
@@ -80,16 +76,12 @@ int fcntl(int fildes, int cmd, ...) {
8076
errno = error;
8177
return -1;
8278
}
83-
#elif defined(__wasip2__)
79+
#elif defined(__wasip2__) || defined(__wasip3__)
8480
if (!entry->vtable->fcntl_setfl) {
8581
errno = EINVAL;
8682
return -1;
8783
}
8884
return entry->vtable->fcntl_setfl(entry->data, flags);
89-
#elif defined(__wasip3__)
90-
// TODO(wasip3)
91-
errno = ENOTSUP;
92-
return -1;
9385
#else
9486
# error "Unknown WASI version"
9587
#endif

libc-bottom-half/cloudlibc/src/libc/poll/poll.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@ static int poll_impl(struct pollfd *fds, size_t nfds, int timeout) {
288288
#elif defined(__wasip3__)
289289

290290
static int poll_impl(struct pollfd *fds, size_t nfds, int timeout) {
291-
// TODO(wasip3)
292291
errno = ENOTSUP;
293292
return -1;
294293
}

libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ int ioctl(int fildes, int request, ...) {
8989
return -1;
9090
}
9191
return 0;
92-
#elif defined(__wasip2__)
92+
#elif defined(__wasip2__) || defined(__wasip3__)
9393
descriptor_table_entry_t *entry = descriptor_table_get_ref(fildes);
9494
va_list ap;
9595
va_start(ap, request);
@@ -101,10 +101,6 @@ int ioctl(int fildes, int request, ...) {
101101
return -1;
102102
}
103103
return entry->vtable->set_blocking(entry->data, blocking);
104-
#elif defined(__wasip3__)
105-
// TODO(wasip3)
106-
errno = ENOTSUP;
107-
return -1;
108104
#else
109105
# error "Unknown WASI version"
110106
#endif

libc-bottom-half/sources/udp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,7 @@ static int udp_poll_register(void *data, poll_state_t *state, short events) {
836836
}
837837
return 0;
838838
}
839+
#endif
839840

840841
static int udp_fcntl_getfl(void *data) {
841842
udp_socket_t *socket = (udp_socket_t *)data;
@@ -855,7 +856,6 @@ static int udp_fcntl_setfl(void *data, int flags) {
855856
}
856857
return 0;
857858
}
858-
#endif
859859

860860
static descriptor_vtable_t udp_vtable = {
861861
.free = udp_free,
@@ -874,8 +874,8 @@ static descriptor_vtable_t udp_vtable = {
874874
.setsockopt = udp_setsockopt,
875875

876876
.poll_register = udp_poll_register,
877+
#endif
877878

878879
.fcntl_getfl = udp_fcntl_getfl,
879880
.fcntl_setfl = udp_fcntl_setfl,
880-
#endif
881881
};

test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ if (NOT (WASI STREQUAL "p1"))
318318
add_wasilibc_test(sockets-nonblocking-udp.c NETWORK FAILP3)
319319
add_wasilibc_test(sockets-nonblocking-multiple.c NETWORK FAILP3)
320320
add_wasilibc_test(sockets-nonblocking-udp-multiple.c NETWORK FAILP3)
321-
add_wasilibc_test(sockets-fcntl.c NETWORK FAILP3)
321+
add_wasilibc_test(sockets-fcntl.c NETWORK)
322322

323323
# TODO: flaky tests
324324
# add_wasilibc_test(sockets-nonblocking.c NETWORK)

0 commit comments

Comments
 (0)