add descriptions to sleep and nanosleep

This commit is contained in:
auronandace
2026-07-05 10:50:57 +01:00
parent fef4343580
commit fe1c4e0135
3 changed files with 25 additions and 3 deletions
+10 -2
View File
@@ -1047,6 +1047,14 @@ pub extern "C" fn setuid(uid: uid_t) -> c_int {
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sleep.html>.
///
/// Causes the calling thread to be suspended from execution until either the
/// number of realtime seconds by the specified argument `seconds` has elapsed
/// or a signal is delivered to the calling thread and its action is to invoke
/// a signal-catching function or to terminate the process.
///
/// Upon success, returns `0`. Upon interruption by a signal, returns the
/// unslept amount in seconds.
#[unsafe(no_mangle)]
pub extern "C" fn sleep(seconds: c_uint) -> c_uint {
let rqtp = timespec {
@@ -1062,8 +1070,8 @@ pub extern "C" fn sleep(seconds: c_uint) -> c_uint {
// If sleep() returns due to delivery of a signal, the return value shall be the "unslept" amount
// (the requested time minus the time actually slept) in seconds.
match unsafe { Sys::nanosleep(&raw const rqtp, &raw mut rmtp) } {
Err(Errno(EINTR)) => rmtp.tv_sec as c_uint,
r => 0,
Err(Errno(_)) => rmtp.tv_sec as c_uint,
_ => 0,
}
}