File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,8 @@ use core::prelude::*;
2020use core:: result:: { Result , Ok , Err } ;
2121use core:: str;
2222
23+ const NSEC_PER_SEC : i32 = 1_000_000_000_i32 ;
24+
2325#[ abi = "cdecl" ]
2426extern mod rustrt {
2527 #[ legacy_exports]
@@ -40,8 +42,17 @@ extern mod rustrt {
4042#[ auto_decode]
4143pub struct Timespec { sec : i64 , nsec : i32 }
4244
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+ */
4353impl Timespec {
4454 static pure fn new( sec: i64 , nsec : i32 ) -> Timespec {
55+ assert nsec >= 0 && nsec < NSEC_PER_SEC ;
4556 Timespec { sec: sec, nsec: nsec }
4657 }
4758}
You can’t perform that action at this time.
0 commit comments