From ee4f346ef0bbbc369dacbf625a1b8099bb5625cb Mon Sep 17 00:00:00 2001 From: Peter Limkilde Svendsen Date: Sun, 2 Feb 2025 22:19:57 +0100 Subject: [PATCH 1/5] 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!(); From ef6b64a7c25f23736a0de77350cd9009ca8aba58 Mon Sep 17 00:00:00 2001 From: Peter Limkilde Svendsen Date: Sun, 2 Feb 2025 22:22:39 +0100 Subject: [PATCH 2/5] Doc and pub use for strptime --- src/header/time/mod.rs | 1 + src/header/time/strptime.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/header/time/mod.rs b/src/header/time/mod.rs index 88160bfecc..8c4baf2159 100644 --- a/src/header/time/mod.rs +++ b/src/header/time/mod.rs @@ -27,6 +27,7 @@ pub mod constants; mod strftime; mod strptime; +pub use strptime::strptime; const YEARS_PER_ERA: time_t = 400; const DAYS_PER_ERA: time_t = 146097; diff --git a/src/header/time/strptime.rs b/src/header/time/strptime.rs index 2e04a19c00..417d8bdb22 100644 --- a/src/header/time/strptime.rs +++ b/src/header/time/strptime.rs @@ -42,6 +42,7 @@ static LONG_MONTHS: [&str; 12] = [ "December", ]; +/// See . #[no_mangle] pub unsafe extern "C" fn strptime( buf: *const c_char, From b0c6991f57e43949f7fed09abefefa61e353bd72 Mon Sep 17 00:00:00 2001 From: Peter Limkilde Svendsen Date: Sun, 2 Feb 2025 22:28:32 +0100 Subject: [PATCH 3/5] Reorder alphabetically --- src/header/time/mod.rs | 68 +++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/header/time/mod.rs b/src/header/time/mod.rs index 8c4baf2159..0880deb7d6 100644 --- a/src/header/time/mod.rs +++ b/src/header/time/mod.rs @@ -107,11 +107,6 @@ 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] @@ -122,6 +117,11 @@ pub static mut daylight: c_int = 0; #[no_mangle] pub static mut timezone: c_long = 0; +/// See . +#[allow(non_upper_case_globals)] +#[no_mangle] +pub static mut tzname: TzName = TzName([ptr::null_mut(); 2]); + /// See . #[repr(C)] pub struct itimerspec { @@ -526,6 +526,12 @@ pub unsafe extern "C" fn time(tloc: *mut time_t) -> time_t { ts.tv_sec } +/// Non-POSIX, see . +#[no_mangle] +pub unsafe extern "C" fn timegm(tm: *mut tm) -> time_t { + mktime(tm) +} + /// Non-POSIX, see . #[deprecated] #[no_mangle] @@ -534,12 +540,6 @@ pub unsafe extern "C" fn timelocal(tm: *mut tm) -> time_t { 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( @@ -556,6 +556,29 @@ pub extern "C" fn timer_delete(timerid: timer_t) -> c_int { unimplemented!(); } +/// See . +// #[no_mangle] +pub extern "C" fn timer_getoverrun(timerid: timer_t) -> c_int { + 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_settime( + timerid: timer_t, + flags: c_int, + value: *const itimerspec, + ovalue: *mut itimerspec, +) -> c_int { + unimplemented!(); +} + /// See . #[no_mangle] pub unsafe extern "C" fn tzset() { @@ -574,29 +597,6 @@ 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, - flags: c_int, - value: *const itimerspec, - ovalue: *mut itimerspec, -) -> c_int { - 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!(); -} - fn clear_timezone(guard: &mut MutexGuard<'_, (Option, Option)>) { guard.0 = None; guard.1 = None; From 3f88c9042d6bdc0ef190395058f51cf1e1222f37 Mon Sep 17 00:00:00 2001 From: Peter Limkilde Svendsen Date: Sun, 2 Feb 2025 22:41:45 +0100 Subject: [PATCH 4/5] Add missing function stubs --- src/header/time/mod.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/header/time/mod.rs b/src/header/time/mod.rs index 0880deb7d6..3d3e8fc18d 100644 --- a/src/header/time/mod.rs +++ b/src/header/time/mod.rs @@ -244,6 +244,12 @@ pub extern "C" fn clock() -> clock_t { } } +/// See . +// #[no_mangle] +pub extern "C" fn clock_getcpuclockid(pid: pid_t, clock_id: clockid_t) -> c_int { + unimplemented!(); +} + /// See . #[no_mangle] pub unsafe extern "C" fn clock_getres(clock_id: clockid_t, tp: *mut timespec) -> c_int { @@ -260,6 +266,12 @@ pub unsafe extern "C" fn clock_gettime(clock_id: clockid_t, tp: *mut timespec) - .or_minus_one_errno() } +/// See . +// #[no_mangle] +pub extern "C" fn clock_nanosleep(clock_id: clockid_t, flags: c_int, rqtp: *const timespec, rmtp: *mut timespec) -> c_int { + unimplemented!(); +} + /// See . #[no_mangle] pub unsafe extern "C" fn clock_settime(clock_id: clockid_t, tp: *const timespec) -> c_int { @@ -515,6 +527,13 @@ pub unsafe extern "C" fn strftime( } } +// See . +// TODO: needs locale_t +// #[no_mangle] +/*pub extern "C" fn strftime_l(s: *mut char, maxsize: size_t, format: *const c_char, timeptr: *const tm, locale: locale_t) -> size_t { + unimplemented!(); +}*/ + /// See . #[no_mangle] pub unsafe extern "C" fn time(tloc: *mut time_t) -> time_t { @@ -579,6 +598,12 @@ pub extern "C" fn timer_settime( unimplemented!(); } +/// See . +// #[no_mangle] +pub extern "C" fn timespec_get(ts: *mut timespec, base: c_int) -> c_int { + unimplemented!(); +} + /// See . #[no_mangle] pub unsafe extern "C" fn tzset() { From 0f0bc8fc5ec73dcb975fcfbe4cbae7f743f366fe Mon Sep 17 00:00:00 2001 From: Peter Limkilde Svendsen Date: Sun, 2 Feb 2025 22:42:05 +0100 Subject: [PATCH 5/5] Formatting --- src/header/time/mod.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/header/time/mod.rs b/src/header/time/mod.rs index 3d3e8fc18d..223a7ab631 100644 --- a/src/header/time/mod.rs +++ b/src/header/time/mod.rs @@ -268,7 +268,12 @@ pub unsafe extern "C" fn clock_gettime(clock_id: clockid_t, tp: *mut timespec) - /// See . // #[no_mangle] -pub extern "C" fn clock_nanosleep(clock_id: clockid_t, flags: c_int, rqtp: *const timespec, rmtp: *mut timespec) -> c_int { +pub extern "C" fn clock_nanosleep( + clock_id: clockid_t, + flags: c_int, + rqtp: *const timespec, + rmtp: *mut timespec, +) -> c_int { unimplemented!(); }