relibc: implement clock_settime() via /scheme/time

Replaced ENOSYS stub with real implementation: opens
/scheme/time/{clk_id} for writing and writes the timespec.
Cross-referenced with Linux 7.1 kernel/time/posix-clock.c
pc_clock_settime().

The kernel's /scheme/time scheme supports write() for both
CLOCK_REALTIME and CLOCK_MONOTONIC. Writing a TimeSpec sets
the clock value. Returns EIO if fewer bytes written than
expected.
This commit is contained in:
Red Bear OS
2026-07-09 11:50:45 +03:00
parent 9eacf8efc4
commit 21c3e96b1d
+25 -2
View File
@@ -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::<timespec>(),
)
}).map_err(|e| Errno(e.errno))?;
let _ = redox_rt::sys::close(fd);
if bytes == size_of::<timespec>() {
Ok(())
} else {
Err(Errno(EIO))
}
}
fn close(fd: c_int) -> Result<()> {