summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
authorнаб <nabijaczleweli@nabijaczleweli.xyz>2020-12-27 18:01:12 +0100
committerнаб <nabijaczleweli@nabijaczleweli.xyz>2021-02-15 18:59:47 +0100
commit90b273439ee02cd484bc73d8201472a889148a74 (patch)
tree11ceaa7977d50456cedc4bc049b930078c05f68b /src/sys
parent1f69c1da2facf7d5d14d290081d58813744c687e (diff)
downloadnix-90b273439ee02cd484bc73d8201472a889148a74.zip
Port timespec to x32
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/time.rs19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/sys/time.rs b/src/sys/time.rs
index bdcfe3c9..7546d1b3 100644
--- a/src/sys/time.rs
+++ b/src/sys/time.rs
@@ -1,7 +1,7 @@
use std::{cmp, fmt, ops};
use std::time::Duration;
use std::convert::From;
-use libc::{c_long, timespec, timeval};
+use libc::{timespec, timeval};
#[cfg_attr(target_env = "musl", allow(deprecated))] // https://github.com/rust-lang/libc/issues/1848
pub use libc::{time_t, suseconds_t};
@@ -62,6 +62,13 @@ const TS_MAX_SECONDS: i64 = ::std::isize::MAX as i64;
const TS_MIN_SECONDS: i64 = -TS_MAX_SECONDS;
+// x32 compatibility
+// See https://sourceware.org/bugzilla/show_bug.cgi?id=16437
+#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
+type timespec_tv_nsec_t = i64;
+#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
+type timespec_tv_nsec_t = libc::c_long;
+
impl From<timespec> for TimeSpec {
fn from(ts: timespec) -> Self {
Self(ts)
@@ -73,7 +80,7 @@ impl From<Duration> for TimeSpec {
#[cfg_attr(target_env = "musl", allow(deprecated))] // https://github.com/rust-lang/libc/issues/1848
TimeSpec(timespec {
tv_sec: duration.as_secs() as time_t,
- tv_nsec: duration.subsec_nanos() as c_long
+ tv_nsec: duration.subsec_nanos() as timespec_tv_nsec_t
})
}
}
@@ -148,7 +155,7 @@ impl TimeValLike for TimeSpec {
"TimeSpec out of bounds");
#[cfg_attr(target_env = "musl", allow(deprecated))] // https://github.com/rust-lang/libc/issues/1848
TimeSpec(timespec {tv_sec: secs as time_t,
- tv_nsec: nanos as c_long })
+ tv_nsec: nanos as timespec_tv_nsec_t })
}
fn num_seconds(&self) -> i64 {
@@ -175,9 +182,9 @@ impl TimeValLike for TimeSpec {
}
impl TimeSpec {
- fn nanos_mod_sec(&self) -> c_long {
+ fn nanos_mod_sec(&self) -> timespec_tv_nsec_t {
if self.tv_sec() < 0 && self.tv_nsec() > 0 {
- self.tv_nsec() - NANOS_PER_SEC as c_long
+ self.tv_nsec() - NANOS_PER_SEC as timespec_tv_nsec_t
} else {
self.tv_nsec()
}
@@ -188,7 +195,7 @@ impl TimeSpec {
self.0.tv_sec
}
- pub fn tv_nsec(&self) -> c_long {
+ pub fn tv_nsec(&self) -> timespec_tv_nsec_t {
self.0.tv_nsec
}
}