1
1
//! `Timespec` and related types, which are used by multiple public API
2
2
//! modules.
3
3
4
+ #[ cfg( not( fix_y2038) ) ]
4
5
use crate :: backend:: c;
5
6
6
7
/// `struct timespec`
@@ -28,18 +29,22 @@ pub type Secs = c::time_t;
28
29
#[ cfg( fix_y2038) ]
29
30
pub type Secs = i64 ;
30
31
31
- /// A type for the `tv_nsec` field of [`Timespec`].
32
- #[ cfg( all( libc, target_arch = "x86_64" , target_pointer_width = "32" ) ) ]
32
+ /// A type for the `tv_sec` field of [`Timespec`].
33
+ #[ cfg( any(
34
+ fix_y2038,
35
+ linux_raw,
36
+ all( libc, target_arch = "x86_64" , target_pointer_width = "32" )
37
+ ) ) ]
33
38
pub type Nsecs = i64 ;
34
39
35
40
/// A type for the `tv_nsec` field of [`Timespec`].
36
- #[ cfg( all( libc, not( all( target_arch = "x86_64" , target_pointer_width = "32" ) ) ) ) ]
41
+ #[ cfg( all(
42
+ not( fix_y2038) ,
43
+ libc,
44
+ not( all( target_arch = "x86_64" , target_pointer_width = "32" ) )
45
+ ) ) ]
37
46
pub type Nsecs = c:: c_long ;
38
47
39
- /// A type for the `tv_nsec` field of [`Timespec`].
40
- #[ cfg( linux_raw) ]
41
- pub type Nsecs = i64 ;
42
-
43
48
/// On 32-bit glibc platforms, `timespec` has anonymous padding fields, which
44
49
/// Rust doesn't support yet (see `unnamed_fields`), so we define our own
45
50
/// struct with explicit padding, with bidirectional `From` impls.
@@ -52,7 +57,7 @@ pub(crate) struct LibcTimespec {
52
57
#[ cfg( target_endian = "big" ) ]
53
58
padding : core:: mem:: MaybeUninit < u32 > ,
54
59
55
- pub ( crate ) tv_nsec : Nsecs ,
60
+ pub ( crate ) tv_nsec : i32 ,
56
61
57
62
#[ cfg( target_endian = "little" ) ]
58
63
padding : core:: mem:: MaybeUninit < u32 > ,
@@ -64,7 +69,7 @@ impl From<LibcTimespec> for Timespec {
64
69
fn from ( t : LibcTimespec ) -> Self {
65
70
Self {
66
71
tv_sec : t. tv_sec ,
67
- tv_nsec : t. tv_nsec ,
72
+ tv_nsec : t. tv_nsec as _ ,
68
73
}
69
74
}
70
75
}
@@ -75,7 +80,7 @@ impl From<Timespec> for LibcTimespec {
75
80
fn from ( t : Timespec ) -> Self {
76
81
Self {
77
82
tv_sec : t. tv_sec ,
78
- tv_nsec : t. tv_nsec ,
83
+ tv_nsec : t. tv_nsec as _ ,
79
84
padding : core:: mem:: MaybeUninit :: uninit ( ) ,
80
85
}
81
86
}
0 commit comments