File tree 1 file changed +11
-0
lines changed
1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,8 @@ use core::prelude::*;
20
20
use core:: result:: { Result , Ok , Err } ;
21
21
use core:: str;
22
22
23
+ const NSEC_PER_SEC : i32 = 1_000_000_000_i32 ;
24
+
23
25
#[ abi = "cdecl" ]
24
26
extern mod rustrt {
25
27
#[ legacy_exports]
@@ -40,8 +42,17 @@ extern mod rustrt {
40
42
#[ auto_decode]
41
43
pub struct Timespec { sec : i64 , nsec : i32 }
42
44
45
+ /*
46
+ * Timespec assumes that pre-epoch Timespecs have negative sec and positive
47
+ * nsec fields. Darwin's and Linux's struct timespec functions handle pre-
48
+ * epoch timestamps using a "two steps back, one step forward" representation,
49
+ * though the man pages do not actually document this. For example, the time
50
+ * -1.2 seconds before the epoch is represented by `Timespec { sec: -2_i64,
51
+ * nsec: 800_000_000_i32 }`.
52
+ */
43
53
impl Timespec {
44
54
static pure fn new( sec: i64 , nsec : i32 ) -> Timespec {
55
+ assert nsec >= 0 && nsec < NSEC_PER_SEC ;
45
56
Timespec { sec: sec, nsec: nsec }
46
57
}
47
58
}
You can’t perform that action at this time.
0 commit comments