use core::ffi::{c_char, c_int};
use arceos_posix_api::{
sys_fstat, sys_getcwd, sys_lseek, sys_lstat, sys_open, sys_rename, sys_stat,
};
use crate::{ctypes, utils::e};
#[no_mangle]
pub unsafe extern "C" fn ax_open(
filename: *const c_char,
flags: c_int,
mode: ctypes::mode_t,
) -> c_int {
e(sys_open(filename, flags, mode))
}
#[no_mangle]
pub unsafe extern "C" fn lseek(fd: c_int, offset: ctypes::off_t, whence: c_int) -> ctypes::off_t {
e(sys_lseek(fd, offset, whence) as _) as _
}
#[no_mangle]
pub unsafe extern "C" fn stat(path: *const c_char, buf: *mut ctypes::stat) -> c_int {
e(sys_stat(path, buf))
}
#[no_mangle]
pub unsafe extern "C" fn fstat(fd: c_int, buf: *mut ctypes::stat) -> c_int {
e(sys_fstat(fd, buf))
}
#[no_mangle]
pub unsafe extern "C" fn lstat(path: *const c_char, buf: *mut ctypes::stat) -> c_int {
e(sys_lstat(path, buf) as _)
}
#[no_mangle]
pub unsafe extern "C" fn getcwd(buf: *mut c_char, size: usize) -> *mut c_char {
sys_getcwd(buf, size)
}
#[no_mangle]
pub unsafe extern "C" fn rename(old: *const c_char, new: *const c_char) -> c_int {
e(sys_rename(old, new))
}