From ee4f346ef0bbbc369dacbf625a1b8099bb5625cb Mon Sep 17 00:00:00 2001 From: Peter Limkilde Svendsen Date: Sun, 2 Feb 2025 22:19:57 +0100 Subject: [PATCH] Add docs and deprecations for time.h --- src/header/time/mod.rs | 59 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/src/header/time/mod.rs b/src/header/time/mod.rs index 5de0898acf..88160bfecc 100644 --- a/src/header/time/mod.rs +++ b/src/header/time/mod.rs @@ -1,4 +1,6 @@ -//! time implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/time.h.html +//! `time.h` implementation. +//! +//! See . use crate::{ c_str::{CStr, CString}, @@ -30,6 +32,7 @@ const YEARS_PER_ERA: time_t = 400; const DAYS_PER_ERA: time_t = 146097; const SECS_PER_DAY: time_t = 24 * 60 * 60; +/// See . #[repr(C)] #[derive(Clone, Copy, Default)] pub struct timespec { @@ -68,6 +71,7 @@ impl<'a> From<&'a timespec> for syscall::TimeSpec { } } +/// See . #[repr(C)] pub struct tm { pub tm_sec: c_int, // 0 - 60 @@ -102,30 +106,48 @@ static TIMEZONE_NAMES: Mutex>> = Mutex::new(OnceCell: // Hold `TIMEZONE_LOCK` when updating `tzname`, `timezone`, and `daylight`. static TIMEZONE_LOCK: Mutex<(Option, Option)> = Mutex::new((None, None)); +/// See . #[allow(non_upper_case_globals)] #[no_mangle] pub static mut tzname: TzName = TzName([ptr::null_mut(); 2]); +/// See . #[allow(non_upper_case_globals)] #[no_mangle] pub static mut daylight: c_int = 0; + +/// See . #[allow(non_upper_case_globals)] #[no_mangle] pub static mut timezone: c_long = 0; +/// See . #[repr(C)] pub struct itimerspec { pub it_interval: timespec, pub it_value: timespec, } +/// See . pub struct sigevent; +/// See . +/// +/// # Deprecation +/// The `asctime()` function was marked obsolescent in the Open Group Base +/// Specifications Issue 7. +#[deprecated] #[no_mangle] pub unsafe extern "C" fn asctime(timeptr: *const tm) -> *mut c_char { asctime_r(timeptr, ASCTIME.as_mut_ptr().cast()) } +/// See . +/// +/// # Deprecation +/// The `asctime_r()` was marked obsolescent in the Open Group Base +/// Specifications Issue 7, and removed in Issue 8. +#[deprecated] #[no_mangle] pub unsafe extern "C" fn asctime_r(tm: *const tm, buf: *mut c_char) -> *mut c_char { let tm_sec = (*tm).tm_sec; @@ -203,6 +225,7 @@ pub unsafe extern "C" fn asctime_r(tm: *const tm, buf: *mut c_char) -> *mut c_ch } } +/// See . #[no_mangle] pub extern "C" fn clock() -> clock_t { let mut ts = mem::MaybeUninit::::uninit(); @@ -220,6 +243,7 @@ pub extern "C" fn clock() -> clock_t { } } +/// See . #[no_mangle] pub unsafe extern "C" fn clock_getres(clock_id: clockid_t, tp: *mut timespec) -> c_int { Sys::clock_getres(clock_id, tp) @@ -227,6 +251,7 @@ pub unsafe extern "C" fn clock_getres(clock_id: clockid_t, tp: *mut timespec) -> .or_minus_one_errno() } +/// See . #[no_mangle] pub unsafe extern "C" fn clock_gettime(clock_id: clockid_t, tp: *mut timespec) -> c_int { Sys::clock_gettime(clock_id, tp) @@ -234,6 +259,7 @@ pub unsafe extern "C" fn clock_gettime(clock_id: clockid_t, tp: *mut timespec) - .or_minus_one_errno() } +/// See . #[no_mangle] pub unsafe extern "C" fn clock_settime(clock_id: clockid_t, tp: *const timespec) -> c_int { Sys::clock_settime(clock_id, tp) @@ -241,11 +267,23 @@ pub unsafe extern "C" fn clock_settime(clock_id: clockid_t, tp: *const timespec) .or_minus_one_errno() } +/// See . +/// +/// # Deprecation +/// The `ctime()` function was marked obsolescent in the Open Group Base +/// Specifications Issue 7. +#[deprecated] #[no_mangle] pub unsafe extern "C" fn ctime(clock: *const time_t) -> *mut c_char { asctime(localtime(clock)) } +/// See . +/// +/// # Deprecation +/// The `ctime_r()` function was marked obsolescent in the Open Group Base +/// Specifications Issue 7, and removed in Issue 8. +#[deprecated] #[no_mangle] pub unsafe extern "C" fn ctime_r(clock: *const time_t, buf: *mut c_char) -> *mut c_char { // Using MaybeUninit seems to cause a panic during the build process @@ -254,21 +292,25 @@ pub unsafe extern "C" fn ctime_r(clock: *const time_t, buf: *mut c_char) -> *mut asctime_r(&tm1, buf) } +/// See . #[no_mangle] pub extern "C" fn difftime(time1: time_t, time0: time_t) -> c_double { (time1 - time0) as _ } +/// See . // #[no_mangle] pub extern "C" fn getdate(string: *const c_char) -> tm { unimplemented!(); } +/// See . #[no_mangle] pub unsafe extern "C" fn gmtime(timer: *const time_t) -> *mut tm { gmtime_r(timer, &mut TM) } +/// See . #[no_mangle] pub unsafe extern "C" fn gmtime_r(clock: *const time_t, result: *mut tm) -> *mut tm { /* For the details of the algorithm used here, see @@ -364,11 +406,13 @@ pub unsafe extern "C" fn gmtime_r(clock: *const time_t, result: *mut tm) -> *mut } } +/// See . #[no_mangle] pub unsafe extern "C" fn localtime(clock: *const time_t) -> *mut tm { localtime_r(clock, &mut TM) } +/// See . #[no_mangle] pub unsafe extern "C" fn localtime_r(clock: *const time_t, t: *mut tm) -> *mut tm { let mut lock = TIMEZONE_LOCK.lock(); @@ -390,6 +434,7 @@ pub unsafe extern "C" fn localtime_r(clock: *const time_t, t: *mut tm) -> *mut t t } +/// See . #[no_mangle] pub unsafe extern "C" fn mktime(timeptr: *mut tm) -> time_t { let mut lock = TIMEZONE_LOCK.lock(); @@ -443,11 +488,13 @@ pub unsafe extern "C" fn mktime(timeptr: *mut tm) -> time_t { timestamp } +/// See . #[no_mangle] pub unsafe extern "C" fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int { Sys::nanosleep(rqtp, rmtp).map(|()| 0).or_minus_one_errno() } +/// See . #[no_mangle] pub unsafe extern "C" fn strftime( s: *mut c_char, @@ -467,6 +514,7 @@ pub unsafe extern "C" fn strftime( } } +/// See . #[no_mangle] pub unsafe extern "C" fn time(tloc: *mut time_t) -> time_t { let mut ts = timespec::default(); @@ -477,17 +525,21 @@ pub unsafe extern "C" fn time(tloc: *mut time_t) -> time_t { ts.tv_sec } +/// Non-POSIX, see . +#[deprecated] #[no_mangle] pub unsafe extern "C" fn timelocal(tm: *mut tm) -> time_t { //TODO: timezone timegm(tm) } +/// Non-POSIX, see . #[no_mangle] pub unsafe extern "C" fn timegm(tm: *mut tm) -> time_t { mktime(tm) } +/// See . // #[no_mangle] pub extern "C" fn timer_create( clock_id: clockid_t, @@ -497,11 +549,13 @@ pub extern "C" fn timer_create( unimplemented!(); } +/// See . // #[no_mangle] pub extern "C" fn timer_delete(timerid: timer_t) -> c_int { unimplemented!(); } +/// See . #[no_mangle] pub unsafe extern "C" fn tzset() { let mut lock = TIMEZONE_LOCK.lock(); @@ -519,6 +573,7 @@ pub unsafe extern "C" fn tzset() { set_timezone(&mut lock, &std_time, dst_time) } +/// See . // #[no_mangle] pub extern "C" fn timer_settime( timerid: timer_t, @@ -529,11 +584,13 @@ pub extern "C" fn timer_settime( unimplemented!(); } +/// See . // #[no_mangle] pub extern "C" fn timer_gettime(timerid: timer_t, value: *mut itimerspec) -> c_int { unimplemented!(); } +/// See . // #[no_mangle] pub extern "C" fn timer_getoverrun(timerid: timer_t) -> c_int { unimplemented!();