diff --git a/src/header/time/cbindgen.toml b/src/header/time/cbindgen.toml index d2476bd3b3..b223e844b8 100644 --- a/src/header/time/cbindgen.toml +++ b/src/header/time/cbindgen.toml @@ -1,4 +1,16 @@ -sys_includes = ["sys/types.h", "stdint.h", "stddef.h", "features.h"] +# POSIX header spec: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/time.h.html +# +# Spec quotations relating to includes: +# - "The header shall define the clock_t, size_t, time_t, types as described in ." +# - "The header shall define the clockid_t and timer_t types as described in ." +# - "The header shall define the locale_t type as described in ." +# - "The header shall define the pid_t type as described in ." +# - "The tag sigevent shall be declared as naming an incomplete structure type, the contents of which are described in the header." +# - "NULL As described in ." +# - "Inclusion of the header may make visible all symbols from the header." +# +# features.h included for deprecated annotations +sys_includes = ["sys/types.h", "stddef.h", "features.h"] include_guard = "_RELIBC_TIME_H" language = "C" style = "Tag" @@ -6,6 +18,8 @@ no_includes = true cpp_compat = true after_includes = """ #include // for timespec +#include // for locale_t from locale.h + struct sigevent; """ diff --git a/src/header/time/constants.rs b/src/header/time/constants.rs index 2b3d3ba645..b44b4116e5 100644 --- a/src/header/time/constants.rs +++ b/src/header/time/constants.rs @@ -10,9 +10,12 @@ pub mod sys; pub use self::sys::*; +/// cbindgen:ignore pub(crate) const UTC: *const c_char = c"UTC".as_ptr().cast(); +/// cbindgen:ignore pub(crate) const DAY_NAMES: [&str; 7] = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; +/// cbindgen:ignore pub(crate) const MON_NAMES: [&str; 12] = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", ]; diff --git a/src/header/time/mod.rs b/src/header/time/mod.rs index 5e8637c33d..979d6a5f84 100644 --- a/src/header/time/mod.rs +++ b/src/header/time/mod.rs @@ -39,10 +39,15 @@ mod strftime; mod strptime; pub use strptime::strptime; +/// cbindgen:ignore const YEARS_PER_ERA: time_t = 400; +/// cbindgen:ignore const DAYS_PER_ERA: time_t = 146097; +/// cbindgen:ignore const SECS_PER_DAY: time_t = 24 * 60 * 60; +/// cbindgen:ignore pub(crate) const NANOSECONDS: c_long = 1_000_000_000; +/// cbindgen:ignore const UTC_STR: &core::ffi::CStr = c"UTC"; /// timer_t internal data, ABI unstable @@ -73,6 +78,7 @@ impl timer_internal_t { } /// See . +#[allow(non_camel_case_types)] #[repr(C)] pub struct tm { pub tm_sec: c_int, // 0 - 60 @@ -90,9 +96,11 @@ pub struct tm { unsafe impl Sync for tm {} +/// cbindgen:ignore // The C Standard says that localtime and gmtime return the same pointer. static GMTIME_LOCALTIME_RETURN_TM: RawCell = RawCell::new(blank_tm()); +/// cbindgen:ignore // The C Standard says that ctime and asctime return the same pointer. static mut ASCTIME: [c_char; 26] = [0; 26]; @@ -101,9 +109,11 @@ pub struct TzName([*mut c_char; 2]); unsafe impl Sync for TzName {} +/// cbindgen:ignore // Name storage for the `tm_zone` field. static TIMEZONE_NAMES: Mutex>> = Mutex::new(OnceCell::new()); +/// cbindgen:ignore // relibc functions should hold `TIMEZONE_LOCK` when accessing `daylight`, // `timezone`, and `tzname`. However, it cannot guard those variables against // user access (see `tzset()` specs for details). @@ -132,6 +142,7 @@ pub static mut tzname: TzName = TzName([ptr::null_mut(); 2]); pub static mut getdate_err: c_int = 0; /// See . +#[allow(non_camel_case_types)] #[repr(C)] #[derive(Clone, Default)] pub struct itimerspec { diff --git a/src/header/time/strptime.rs b/src/header/time/strptime.rs index f49c5b54b6..b4e3d35904 100644 --- a/src/header/time/strptime.rs +++ b/src/header/time/strptime.rs @@ -11,8 +11,10 @@ use core::{ str, }; +/// cbindgen:ignore /// For convenience, we define some helper constants for the C-locale. const SHORT_DAYS: [&str; 7] = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; +/// cbindgen:ignore const LONG_DAYS: [&str; 7] = [ "Sunday", "Monday", @@ -22,9 +24,11 @@ const LONG_DAYS: [&str; 7] = [ "Friday", "Saturday", ]; +/// cbindgen:ignore const SHORT_MONTHS: [&str; 12] = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", ]; +/// cbindgen:ignore const LONG_MONTHS: [&str; 12] = [ "January", "February",