From 9b640d53f5b72bedfd6cd589f77d9338d5b540f3 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Mon, 16 Mar 2015 15:26:06 -0700 Subject: Fix on 32bit platforms --- src/sys/time.rs | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'src/sys/time.rs') diff --git a/src/sys/time.rs b/src/sys/time.rs index fbe17c49..f66605c7 100644 --- a/src/sys/time.rs +++ b/src/sys/time.rs @@ -1,6 +1,5 @@ use std::{fmt, ops}; use std::num::Int; -use std::i64; use libc::{time_t, suseconds_t}; #[repr(C)] @@ -14,15 +13,13 @@ const MICROS_PER_SEC: i64 = 1_000_000; const SECS_PER_MINUTE: i64 = 60; const SECS_PER_HOUR: i64 = 3600; -const MIN: TimeVal = TimeVal { - tv_sec: -(i64::MAX / MICROS_PER_SEC - 1), - tv_usec: (-(MICROS_PER_SEC - 1)) as suseconds_t, -}; +#[cfg(target_pointer_width = "64")] +const MAX_SECONDS: i64 = (::std::i64::MAX / MICROS_PER_SEC) - 1; -const MAX: TimeVal = TimeVal { - tv_sec: i64::MAX / MICROS_PER_SEC - 1, - tv_usec: (MICROS_PER_SEC - 1) as suseconds_t, -}; +#[cfg(target_pointer_width = "32")] +const MAX_SECONDS: i64 = ::std::isize::MAX as i64; + +const MIN_SECONDS: i64 = -MAX_SECONDS; impl TimeVal { #[inline] @@ -48,9 +45,8 @@ impl TimeVal { #[inline] pub fn seconds(seconds: i64) -> TimeVal { - let ret = TimeVal { tv_sec: seconds, tv_usec: 0 }; - assert!(ret >= MIN && ret <= MAX, "TimeVal out of bounds"); - ret + assert!(seconds >= MIN_SECONDS && seconds <= MAX_SECONDS, "TimeVal out of bounds; seconds={}", seconds); + TimeVal { tv_sec: seconds as time_t, tv_usec: 0 } } #[inline] @@ -66,9 +62,8 @@ impl TimeVal { #[unstable(feature = "std_misc")] pub fn microseconds(microseconds: i64) -> TimeVal { let (secs, micros) = div_mod_floor_64(microseconds, MICROS_PER_SEC); - let ret = TimeVal { tv_sec: secs, tv_usec: micros as suseconds_t }; - assert!(ret >= MIN && ret <= MAX, "TimeVal out of bounds"); - ret + assert!(secs >= MIN_SECONDS && secs <= MAX_SECONDS, "TimeVal out of bounds"); + TimeVal { tv_sec: secs as time_t, tv_usec: micros as suseconds_t } } pub fn num_hours(&self) -> i64 { @@ -81,9 +76,9 @@ impl TimeVal { pub fn num_seconds(&self) -> i64 { if self.tv_sec < 0 && self.tv_usec > 0 { - self.tv_sec + 1 + (self.tv_sec + 1) as i64 } else { - self.tv_sec + self.tv_sec as i64 } } -- cgit v1.2.3