Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,35 @@
#![allow(non_upper_case_globals)]
#![no_std]

use libc::{FILE, pid_t, pollfd, timespec, timeval};
use core::mem::zeroed;

use libc::{FILE, pid_t, pollfd, timeval};

#[derive(Copy, Clone)]
#[repr(C)]
pub union timespec {
t: libc::timespec,
t64: [i64; 2],
}

#[cfg(not(target_pointer_width = "32"))]
impl timespec {
#[inline(always)]
pub fn tv_sec(&self) -> i64 { unsafe { self.t.tv_sec as i64 } }
#[inline(always)]
pub fn tv_nsec(&self) -> i64 { unsafe { self.t.tv_nsec as i64 } }
}

#[cfg(target_pointer_width = "32")]
impl timespec {
unsafe fn is64(&self) -> bool { self.t64[1] != 0 }
pub fn tv_sec(&self) -> i64 { unsafe { if self.is64() { self.t64[0] } else { self.t.tv_sec as i64 } } }
pub fn tv_nsec(&self) -> i64 { unsafe { if self.is64() { self.t64[1] } else { self.t.tv_nsec as i64 } } }
}

impl Default for timespec {
fn default() -> Self { unsafe { zeroed() } }
}
Comment on lines +10 to +34

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The LLM has got a point, but the proposed fix would just recreate the segfault that we're trying to address.


#[cfg(feature = "use-bindgen")]
include!(concat!(env!("OUT_DIR"), "/generated.rs"));
Expand Down