diff --git a/src/platform/redox/mod.rs b/src/platform/redox/mod.rs index 6521d5b818..5166c82541 100644 --- a/src/platform/redox/mod.rs +++ b/src/platform/redox/mod.rs @@ -264,8 +264,31 @@ impl Pal for Sys { } unsafe fn clock_settime(clk_id: clockid_t, tp: *const timespec) -> Result<()> { - todo_skip!(0, "clock_settime({}, {:p}): not implemented", clk_id, tp); - Err(Errno(ENOSYS)) + // Write the timespec to /scheme/time/{clk_id} to set the clock. + // Cross-referenced with Linux 7.1 kernel/time/posix-clock.c + // pc_clock_settime() which writes to the clock device. + if tp.is_null() { + return Err(Errno(EFAULT)); + } + let ts = unsafe { *tp }; + let path = format!("/scheme/time/{}", clk_id as usize); + let fd = redox_rt::sys::open( + &path, + syscall::O_WRONLY | syscall::O_CLOEXEC, + 0, + ).map_err(|e| Errno(e.errno))?; + let bytes = redox_rt::sys::write(fd, unsafe { + core::slice::from_raw_parts( + &ts as *const timespec as *const u8, + size_of::(), + ) + }).map_err(|e| Errno(e.errno))?; + let _ = redox_rt::sys::close(fd); + if bytes == size_of::() { + Ok(()) + } else { + Err(Errno(EIO)) + } } fn close(fd: c_int) -> Result<()> {