]> git.proxmox.com Git - wasi-libc.git/blob - libc-bottom-half/cloudlibc/src/libc/unistd/read.c
Wasi snapshot preview1 (#140)
[wasi-libc.git] / libc-bottom-half / cloudlibc / src / libc / unistd / read.c
1 // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/
2 //
3 // SPDX-License-Identifier: BSD-2-Clause
4
5 #include <wasi/api.h>
6 #include <errno.h>
7 #include <unistd.h>
8
9 ssize_t read(int fildes, void *buf, size_t nbyte) {
10 __wasi_iovec_t iov = {.buf = buf, .buf_len = nbyte};
11 size_t bytes_read;
12 __wasi_errno_t error = __wasi_fd_read(fildes, &iov, 1, &bytes_read);
13 if (error != 0) {
14 errno = error == ENOTCAPABLE ? EBADF : error;
15 return -1;
16 }
17 return bytes_read;
18 }