Skip to content

Commit c77b756

Browse files
committed
Remove remaining uses of wasip1 functions with wasip2 defined
1 parent 6c283b5 commit c77b756

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ int ioctl(int fildes, int request, ...) {
6868

6969
switch (request) {
7070
case FIONREAD: {
71+
#ifdef __wasilibc_use_wasip2
72+
// wasip2 doesn't support this operation
73+
errno = ENOTSUP;
74+
return -1;
75+
#else
7176
// Poll the file descriptor to determine how many bytes can be read.
7277
__wasi_subscription_t subscriptions[2] = {
7378
{
@@ -110,8 +115,14 @@ int ioctl(int fildes, int request, ...) {
110115
// No data available for reading.
111116
*result = 0;
112117
return 0;
118+
#endif
113119
}
114120
case FIONBIO: {
121+
#ifdef __wasilibc_use_wasip2
122+
// wasip2 doesn't support setting the non-blocking flag
123+
errno = ENOTSUP;
124+
return -1;
125+
#else
115126
// Obtain the current file descriptor flags.
116127
__wasi_fdstat_t fds;
117128
__wasi_errno_t error = __wasi_fd_fdstat_get(fildes, &fds);
@@ -136,6 +147,7 @@ int ioctl(int fildes, int request, ...) {
136147
return -1;
137148
}
138149
return 0;
150+
#endif
139151
}
140152
default:
141153
// Invalid request.

libc-bottom-half/cloudlibc/src/libc/sys/uio/readv.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,15 @@ ssize_t readv(int fildes, const struct iovec *iov, int iovcnt) {
3030
return -1;
3131
}
3232
size_t bytes_read;
33+
#ifdef __wasilibc_use_wasip2
34+
return preadv(fildes, iov, iovcnt, 0);
35+
#else
3336
__wasi_errno_t error = __wasi_fd_read(
3437
fildes, (const __wasi_iovec_t *)iov, iovcnt, &bytes_read);
3538
if (error != 0) {
3639
errno = error;
3740
return -1;
3841
}
42+
#endif
3943
return bytes_read;
4044
}

libc-bottom-half/sources/__wasilibc_fd_renumber.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ int close(int fd) {
114114

115115
return 0;
116116
}
117-
#endif // __wasilibc_use_wasip2
118-
117+
#else
119118
__wasi_errno_t error = __wasi_fd_close(fd);
120119
if (error != 0) {
121120
errno = error;
122121
return -1;
123122
}
123+
#endif // __wasilibc_use_wasip2
124124

125125
return 0;
126126
}

0 commit comments

Comments
 (0)