1
1
use std:: { cmp, fmt, ops} ;
2
2
use std:: time:: Duration ;
3
3
use std:: convert:: From ;
4
- use libc:: { c_long , timespec, timeval} ;
4
+ use libc:: { timespec, timeval} ;
5
5
#[ cfg_attr( target_env = "musl" , allow( deprecated) ) ] // https://github.com/rust-lang/libc/issues/1848
6
6
pub use libc:: { time_t, suseconds_t} ;
7
7
@@ -62,6 +62,13 @@ const TS_MAX_SECONDS: i64 = ::std::isize::MAX as i64;
62
62
63
63
const TS_MIN_SECONDS : i64 = -TS_MAX_SECONDS ;
64
64
65
+ // x32 compatibility
66
+ // See https://sourceware.org/bugzilla/show_bug.cgi?id=16437
67
+ #[ cfg( all( target_arch = "x86_64" , target_pointer_width = "32" ) ) ]
68
+ type timespec_tv_nsec_t = i64 ;
69
+ #[ cfg( not( all( target_arch = "x86_64" , target_pointer_width = "32" ) ) ) ]
70
+ type timespec_tv_nsec_t = libc:: c_long ;
71
+
65
72
impl From < timespec > for TimeSpec {
66
73
fn from ( ts : timespec ) -> Self {
67
74
Self ( ts)
@@ -73,7 +80,7 @@ impl From<Duration> for TimeSpec {
73
80
#[ cfg_attr( target_env = "musl" , allow( deprecated) ) ] // https://github.com/rust-lang/libc/issues/1848
74
81
TimeSpec ( timespec {
75
82
tv_sec : duration. as_secs ( ) as time_t ,
76
- tv_nsec : duration. subsec_nanos ( ) as c_long
83
+ tv_nsec : duration. subsec_nanos ( ) as timespec_tv_nsec_t
77
84
} )
78
85
}
79
86
}
@@ -148,7 +155,7 @@ impl TimeValLike for TimeSpec {
148
155
"TimeSpec out of bounds" ) ;
149
156
#[ cfg_attr( target_env = "musl" , allow( deprecated) ) ] // https://github.com/rust-lang/libc/issues/1848
150
157
TimeSpec ( timespec { tv_sec : secs as time_t ,
151
- tv_nsec : nanos as c_long } )
158
+ tv_nsec : nanos as timespec_tv_nsec_t } )
152
159
}
153
160
154
161
fn num_seconds ( & self ) -> i64 {
@@ -175,9 +182,9 @@ impl TimeValLike for TimeSpec {
175
182
}
176
183
177
184
impl TimeSpec {
178
- fn nanos_mod_sec ( & self ) -> c_long {
185
+ fn nanos_mod_sec ( & self ) -> timespec_tv_nsec_t {
179
186
if self . tv_sec ( ) < 0 && self . tv_nsec ( ) > 0 {
180
- self . tv_nsec ( ) - NANOS_PER_SEC as c_long
187
+ self . tv_nsec ( ) - NANOS_PER_SEC as timespec_tv_nsec_t
181
188
} else {
182
189
self . tv_nsec ( )
183
190
}
@@ -188,7 +195,7 @@ impl TimeSpec {
188
195
self . 0 . tv_sec
189
196
}
190
197
191
- pub fn tv_nsec ( & self ) -> c_long {
198
+ pub fn tv_nsec ( & self ) -> timespec_tv_nsec_t {
192
199
self . 0 . tv_nsec
193
200
}
194
201
}
0 commit comments