Skip to content

Commit f387a8c

Browse files
rvolosatovsalexcrichton
authored andcommitted
p3: implement fcntl
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
1 parent e50614a commit f387a8c

5 files changed

Lines changed: 9 additions & 23 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: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ typedef struct {
1818
#elif defined(__wasip3__)
1919
int dummy;
2020
#else
21-
#error "Unsupported WASI version"
21+
# error "Unsupported WASI version"
2222
#endif
2323
} udp_socket_streams_t;
2424

@@ -102,8 +102,7 @@ static int udp_create_streams(udp_socket_t *socket,
102102
abort();
103103
}
104104

105-
sockets_borrow_udp_socket_t socket_borrow =
106-
sockets_borrow_udp_socket(socket->socket);
105+
sockets_borrow_udp_socket_t socket_borrow = sockets_borrow_udp_socket(socket->socket);
107106

108107
udp_socket_streams_t *dst;
109108
if (remote_address != NULL) {
@@ -836,6 +835,7 @@ static int udp_poll_register(void *data, poll_state_t *state, short events) {
836835
}
837836
return 0;
838837
}
838+
#endif
839839

840840
static int udp_fcntl_getfl(void *data) {
841841
udp_socket_t *socket = (udp_socket_t *)data;
@@ -855,7 +855,6 @@ static int udp_fcntl_setfl(void *data, int flags) {
855855
}
856856
return 0;
857857
}
858-
#endif
859858

860859
static descriptor_vtable_t udp_vtable = {
861860
.free = udp_free,
@@ -874,8 +873,8 @@ static descriptor_vtable_t udp_vtable = {
874873
.setsockopt = udp_setsockopt,
875874

876875
.poll_register = udp_poll_register,
876+
#endif
877877

878878
.fcntl_getfl = udp_fcntl_getfl,
879879
.fcntl_setfl = udp_fcntl_setfl,
880-
#endif
881880
};

test/CMakeLists.txt

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

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

0 commit comments

Comments
 (0)