diff --git a/c-scape/src/fs/fallocate.rs b/c-scape/src/fs/fallocate.rs new file mode 100644 index 0000000..2c2d47d --- /dev/null +++ b/c-scape/src/fs/fallocate.rs @@ -0,0 +1,16 @@ +use crate::convert_res; +use libc::{c_int, off_t}; +use rustix::fd::BorrowedFd; +use rustix::fs::FallocateFlags; + +#[no_mangle] +unsafe extern "C" fn fallocate(fd: c_int, mode: c_int, offset: off_t, len: off_t) -> c_int { + libc!(libc::fallocate(fd, mode, offset, len)); + + let fd = BorrowedFd::borrow_raw(fd); + let mode = FallocateFlags::from_bits_retain(mode as _); + match convert_res(rustix::fs::fallocate(fd, mode, offset as _, len as _)) { + Some(()) => 0, + None => -1, + } +} diff --git a/c-scape/src/fs/mod.rs b/c-scape/src/fs/mod.rs index a690b3d..f8871b8 100644 --- a/c-scape/src/fs/mod.rs +++ b/c-scape/src/fs/mod.rs @@ -3,6 +3,7 @@ mod access; mod chmod; mod dir; mod fadvise; +mod fallocate; mod fcntl; mod flock; mod inotify; diff --git a/c-scape/src/time/mod.rs b/c-scape/src/time/mod.rs index 5d680be..631ca78 100644 --- a/c-scape/src/time/mod.rs +++ b/c-scape/src/time/mod.rs @@ -126,3 +126,17 @@ unsafe extern "C" fn difftime(time1: libc::time_t, time0: libc::time_t) -> f64 { (time1 as i128 - time0 as i128) as f64 } + +#[no_mangle] +unsafe extern "C" fn clock() -> libc::clock_t { + //libc!(libc::clock()); + + let time = rustix::time::clock_gettime(rustix::time::ClockId::ProcessCPUTime); + + time.tv_sec + .checked_mul(1_000_000) + .map(|usec| usec + time.tv_nsec / 1000) + .unwrap_or(-1) + .try_into() + .unwrap_or(-1) +}