Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement missing unistd readv() #9631

Merged
merged 3 commits into from Oct 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions system/lib/libc/musl/src/unistd/readv.c
Expand Up @@ -4,5 +4,13 @@

ssize_t readv(int fd, const struct iovec *iov, int count)
{
#if __EMSCRIPTEN__
size_t num;
if (__wasi_syscall_ret(__wasi_fd_read(fd, (struct __wasi_iovec_t*)iov, count, &num))) {
num = -1;
}
return num;
#else
return syscall_cp(SYS_readv, fd, iov, count);
#endif
}
21 changes: 21 additions & 0 deletions tests/unistd/io.c
Expand Up @@ -10,6 +10,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/uio.h>
#include <emscripten.h>

int main() {
Expand Down Expand Up @@ -188,5 +189,25 @@ int main() {
}
printf("\n");

// readv
printf("\n");
memset(readBuffer, 0, sizeof readBuffer);
struct iovec iov;
iov.iov_base = readBuffer;
iov.iov_len = sizeof readBuffer;
printf("seek: %d\n", lseek(f, 0, SEEK_SET));
printf("read after write: %d\n", bytesRead = readv(f, &iov, 1));
printf("errno: %d\n", errno);
errno = 0;
printf("final: ");
for (int i = 0; i < bytesRead; i++) {
if (readBuffer[i] == 0) {
printf("\\0");
} else {
printf("%c", readBuffer[i]);
}
}
printf("\n");

return 0;
}
5 changes: 5 additions & 0 deletions tests/unistd/io.out
Expand Up @@ -78,3 +78,8 @@ seek: 0
read after write: 37
errno: 0
final: wri4567890wri\0\0\0\0ite\0\0\0writeme\0\0write

seek: 0
read after write: 37
errno: 0
final: wri4567890wri\0\0\0\0ite\0\0\0writeme\0\0write