axlibc/
io.rs

1use core::ffi::{c_int, c_void};
2
3use arceos_posix_api::{sys_read, sys_write, sys_writev};
4
5use crate::{ctypes, utils::e};
6
7/// Read data from the file indicated by `fd`.
8///
9/// Return the read size if success.
10#[unsafe(no_mangle)]
11pub unsafe extern "C" fn read(fd: c_int, buf: *mut c_void, count: usize) -> ctypes::ssize_t {
12    e(sys_read(fd, buf, count) as _) as _
13}
14
15/// Write data to the file indicated by `fd`.
16///
17/// Return the written size if success.
18#[unsafe(no_mangle)]
19#[cfg(not(test))]
20pub unsafe extern "C" fn write(fd: c_int, buf: *const c_void, count: usize) -> ctypes::ssize_t {
21    e(sys_write(fd, buf, count) as _) as _
22}
23
24/// Write a vector.
25#[unsafe(no_mangle)]
26pub unsafe extern "C" fn writev(
27    fd: c_int,
28    iov: *const ctypes::iovec,
29    iocnt: c_int,
30) -> ctypes::ssize_t {
31    e(sys_writev(fd, iov, iocnt) as _) as _
32}