Rustify Sys::open and some fs:: error handling.
This commit is contained in:
@@ -230,12 +230,12 @@ impl Pal for Sys {
|
||||
Self::readlink(CStr::from_bytes_with_nul(&proc_path).unwrap(), out)
|
||||
}
|
||||
|
||||
fn fsync(fildes: c_int) -> c_int {
|
||||
e(unsafe { syscall!(FSYNC, fildes) }) as c_int
|
||||
fn fsync(fildes: c_int) -> Result<(), Errno> {
|
||||
e_raw(unsafe { syscall!(FSYNC, fildes) }).map(|_| ())
|
||||
}
|
||||
|
||||
fn ftruncate(fildes: c_int, length: off_t) -> c_int {
|
||||
e(unsafe { syscall!(FTRUNCATE, fildes, length) }) as c_int
|
||||
fn ftruncate(fildes: c_int, length: off_t) -> Result<(), Errno> {
|
||||
e_raw(unsafe { syscall!(FTRUNCATE, fildes, length) }).map(|_| ())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -450,8 +450,9 @@ impl Pal for Sys {
|
||||
e(unsafe { syscall!(NANOSLEEP, rqtp, rmtp) }) as c_int
|
||||
}
|
||||
|
||||
fn open(path: CStr, oflag: c_int, mode: mode_t) -> c_int {
|
||||
e(unsafe { syscall!(OPENAT, AT_FDCWD, path.as_ptr(), oflag, mode) }) as c_int
|
||||
fn open(path: CStr, oflag: c_int, mode: mode_t) -> Result<c_int, Errno> {
|
||||
e_raw(unsafe { syscall!(OPENAT, AT_FDCWD, path.as_ptr(), oflag, mode) })
|
||||
.map(|fd| fd as c_int)
|
||||
}
|
||||
|
||||
fn pipe2(fildes: &mut [c_int], flags: c_int) -> c_int {
|
||||
|
||||
@@ -76,9 +76,9 @@ pub trait Pal {
|
||||
|
||||
fn fpath(fildes: c_int, out: &mut [u8]) -> ssize_t;
|
||||
|
||||
fn fsync(fildes: c_int) -> c_int;
|
||||
fn fsync(fildes: c_int) -> Result<(), Errno>;
|
||||
|
||||
fn ftruncate(fildes: c_int, length: off_t) -> c_int;
|
||||
fn ftruncate(fildes: c_int, length: off_t) -> Result<(), Errno>;
|
||||
|
||||
unsafe fn futex_wait(
|
||||
addr: *mut u32,
|
||||
@@ -179,12 +179,13 @@ pub trait Pal {
|
||||
|
||||
fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int;
|
||||
|
||||
fn open(path: CStr, oflag: c_int, mode: mode_t) -> c_int;
|
||||
fn open(path: CStr, oflag: c_int, mode: mode_t) -> Result<c_int, Errno>;
|
||||
|
||||
fn pipe2(fildes: &mut [c_int], flags: c_int) -> c_int;
|
||||
|
||||
unsafe fn rlct_clone(stack: *mut usize) -> Result<crate::pthread::OsTid, Errno>;
|
||||
unsafe fn rlct_kill(os_tid: crate::pthread::OsTid, signal: usize) -> Result<(), Errno>;
|
||||
|
||||
fn current_os_tid() -> crate::pthread::OsTid;
|
||||
|
||||
fn read(fildes: c_int, buf: &mut [u8]) -> Result<ssize_t, Errno>;
|
||||
|
||||
@@ -53,7 +53,7 @@ fn event_flags_to_epoll(flags: syscall::EventFlags) -> c_uint {
|
||||
|
||||
impl PalEpoll for Sys {
|
||||
fn epoll_create1(flags: c_int) -> c_int {
|
||||
Sys::open(c_str!("/scheme/event"), O_RDWR | flags, 0)
|
||||
Sys::open(c_str!("/scheme/event"), O_RDWR | flags, 0).or_minus_one_errno()
|
||||
}
|
||||
|
||||
fn epoll_ctl(epfd: c_int, op: c_int, fd: c_int, event: *mut epoll_event) -> c_int {
|
||||
|
||||
@@ -294,12 +294,14 @@ impl Pal for Sys {
|
||||
unsafe { e(libredox::fstatvfs(fildes as usize, buf).map(|()| 0)) as c_int }
|
||||
}
|
||||
|
||||
fn fsync(fd: c_int) -> c_int {
|
||||
e(syscall::fsync(fd as usize)) as c_int
|
||||
fn fsync(fd: c_int) -> Result<(), Errno> {
|
||||
syscall::fsync(fd as usize)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn ftruncate(fd: c_int, len: off_t) -> c_int {
|
||||
e(syscall::ftruncate(fd as usize, len as usize)) as c_int
|
||||
fn ftruncate(fd: c_int, len: off_t) -> Result<(), Errno> {
|
||||
syscall::ftruncate(fd as usize, len as usize)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -777,10 +779,10 @@ impl Pal for Sys {
|
||||
}
|
||||
}
|
||||
|
||||
fn open(path: CStr, oflag: c_int, mode: mode_t) -> c_int {
|
||||
let path = path_from_c_str!(path);
|
||||
fn open(path: CStr, oflag: c_int, mode: mode_t) -> Result<c_int, Errno> {
|
||||
let path = path.to_str().map_err(|_| Errno(EINVAL))?;
|
||||
|
||||
e(libredox::open(path, oflag, mode)) as c_int
|
||||
Ok(libredox::open(path, oflag, mode)? as c_int)
|
||||
}
|
||||
|
||||
fn pipe2(fds: &mut [c_int], flags: c_int) -> c_int {
|
||||
|
||||
Reference in New Issue
Block a user