Skip to content

Commit 6c283b5

Browse files
committed
Add comments and test for ioctl()
1 parent ba6e9f2 commit 6c283b5

File tree

2 files changed

+43
-7
lines changed
  • libc-bottom-half/cloudlibc/src/libc/sys/ioctl
  • test/src/misc

2 files changed

+43
-7
lines changed

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ int ioctl(int fildes, int request, ...) {
5757
return -1;
5858
}
5959
}
60-
60+
// TODO: In particular, this doesn't support using FIONREAD
61+
// with file descriptors
6162
default:
6263
errno = ENOPROTOOPT;
6364
return -1;
@@ -111,11 +112,6 @@ int ioctl(int fildes, int request, ...) {
111112
return 0;
112113
}
113114
case FIONBIO: {
114-
#ifdef __wasilibc_use_wasip2
115-
// wasip2 doesn't support setting the non-blocking flag
116-
errno = ENOTSUP;
117-
return -1;
118-
#else
119115
// Obtain the current file descriptor flags.
120116
__wasi_fdstat_t fds;
121117
__wasi_errno_t error = __wasi_fd_fdstat_get(fildes, &fds);
@@ -140,7 +136,6 @@ int ioctl(int fildes, int request, ...) {
140136
return -1;
141137
}
142138
return 0;
143-
#endif
144139
}
145140
default:
146141
// Invalid request.

test/src/misc/ioctl.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//! add-flags.py(RUN): --dir fs::/ --wasi=inherit-network=y
2+
3+
#include <errno.h>
4+
#include <stdio.h>
5+
#include <stdlib.h>
6+
#include <string.h>
7+
#include <sys/socket.h>
8+
#include <netinet/in.h>
9+
#include <sys/ioctl.h>
10+
#include <fcntl.h>
11+
#include "test.h"
12+
13+
#define TEST(c) do { \
14+
errno = 0; \
15+
if (!(c)) \
16+
t_error("%s failed (errno = %d)\n", #c, errno); \
17+
} while(0)
18+
19+
int main(void)
20+
{
21+
char tmp[] = "testsuite-XXXXXX";
22+
int fd;
23+
int nbytes = 0;
24+
int flags = 0;
25+
flags |= O_RDWR | O_CREAT | O_EXCL;
26+
27+
TEST((fd = open(tmp, flags, 0600)) > 2);
28+
TEST(write(fd, "hello", 6)==6);
29+
30+
#ifdef __wasilibc_use_wasip2
31+
// Not supported on wasip2
32+
TEST(ioctl(fd, FIONREAD, &nbytes)==-1);
33+
#else
34+
// Always returns 0?
35+
TEST(ioctl(fd, FIONREAD, &nbytes)==0);
36+
#endif
37+
close(fd);
38+
TEST(unlink(tmp)==0);
39+
40+
return t_status;
41+
}

0 commit comments

Comments
 (0)