summaryrefslogtreecommitdiff
path: root/src/sys/time.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-02-20 19:59:26 +0000
committerGitHub <noreply@github.com>2021-02-20 19:59:26 +0000
commit661738cceee4e479ded272a63e3082035b860351 (patch)
treecd7d5d6345777cef2c47561274ab04e7364762a7 /src/sys/time.rs
parentde43d7641b351ff2582206798b68baeed42c3117 (diff)
parent7cdae09e2957f8578c9b8cd88934c669a2f3a13b (diff)
downloadnix-661738cceee4e479ded272a63e3082035b860351.zip
Merge #1366
1366: x32 port r=asomers a=nabijaczleweli I played pretty loose with the statfs bit, hoping for CI to tell me if I broke something. Co-authored-by: наб <nabijaczleweli@nabijaczleweli.xyz>
Diffstat (limited to 'src/sys/time.rs')
-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
}
}