diff options
Diffstat (limited to 'vendor/rustix/src/timespec.rs')
-rw-r--r-- | vendor/rustix/src/timespec.rs | 68 |
1 files changed, 35 insertions, 33 deletions
diff --git a/vendor/rustix/src/timespec.rs b/vendor/rustix/src/timespec.rs index 55c4c061b..51c2d2443 100644 --- a/vendor/rustix/src/timespec.rs +++ b/vendor/rustix/src/timespec.rs @@ -4,19 +4,11 @@ use crate::backend::c; /// `struct timespec` -#[cfg(not(all( - libc, - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -)))] +#[cfg(not(fix_y2038))] pub type Timespec = c::timespec; /// `struct timespec` -#[cfg(all( - libc, - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(fix_y2038)] #[derive(Debug, Clone, Copy)] #[repr(C)] pub struct Timespec { @@ -28,18 +20,12 @@ pub struct Timespec { } /// A type for the `tv_sec` field of [`Timespec`]. -#[cfg(not(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -)))] +#[cfg(not(fix_y2038))] #[allow(deprecated)] pub type Secs = c::time_t; /// A type for the `tv_sec` field of [`Timespec`]. -#[cfg(all( - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(fix_y2038)] pub type Secs = i64; /// A type for the `tv_nsec` field of [`Timespec`]. @@ -57,11 +43,7 @@ pub type Nsecs = i64; /// On 32-bit glibc platforms, `timespec` has anonymous padding fields, which /// Rust doesn't support yet (see `unnamed_fields`), so we define our own /// struct with explicit padding, with bidirectional `From` impls. -#[cfg(all( - libc, - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(fix_y2038)] #[repr(C)] #[derive(Debug, Clone)] pub(crate) struct LibcTimespec { @@ -76,11 +58,7 @@ pub(crate) struct LibcTimespec { padding: core::mem::MaybeUninit<u32>, } -#[cfg(all( - libc, - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(fix_y2038)] impl From<LibcTimespec> for Timespec { #[inline] fn from(t: LibcTimespec) -> Self { @@ -91,11 +69,7 @@ impl From<LibcTimespec> for Timespec { } } -#[cfg(all( - libc, - any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), - target_env = "gnu", -))] +#[cfg(fix_y2038)] impl From<Timespec> for LibcTimespec { #[inline] fn from(t: Timespec) -> Self { @@ -106,3 +80,31 @@ impl From<Timespec> for LibcTimespec { } } } + +#[test] +fn test_sizes() { + assert_eq_size!(Secs, u64); + const_assert!(core::mem::size_of::<Timespec>() >= core::mem::size_of::<(u64, u32)>()); + const_assert!(core::mem::size_of::<Nsecs>() >= 4); + + let mut t = Timespec { + tv_sec: 0, + tv_nsec: 0, + }; + + // `tv_nsec` needs to be able to hold nanoseconds up to a second. + t.tv_nsec = 999_999_999_u32 as _; + assert_eq!(t.tv_nsec as u64, 999_999_999_u64); + + // `tv_sec` needs to be able to hold more than 32-bits of seconds. + t.tv_sec = 0x1_0000_0000_u64 as _; + assert_eq!(t.tv_sec as u64, 0x1_0000_0000_u64); +} + +// Test that our workarounds are needed. +#[cfg(fix_y2038)] +#[test] +#[allow(deprecated)] +fn test_fix_y2038() { + assert_eq_size!(libc::time_t, u32); +} |