@@ -334,7 +334,7 @@ extension timespec {
334
334
@available ( SwiftStdlib 5 . 7 , * )
335
335
public init ( _ duration: Duration ) {
336
336
let comps = duration. components
337
- self . init ( tv_sec: Int ( comps. seconds) ,
337
+ self . init ( tv_sec: time_t ( comps. seconds) ,
338
338
tv_nsec: Int ( comps. attoseconds / 1_000_000_000 ) )
339
339
}
340
340
}
@@ -352,9 +352,19 @@ extension timeval {
352
352
@available ( SwiftStdlib 5 . 7 , * )
353
353
public init ( _ duration: Duration ) {
354
354
let comps = duration. components
355
- // Linux platforms define timeval as Int/Int
356
- self . init ( tv_sec: Int ( comps. seconds) ,
357
- tv_usec: Int ( comps. attoseconds / 1_000_000_000_000 ) )
355
+ #if os(Linux)
356
+ // Linux platforms define timeval as Int/Int, except on 32-bit platforms
357
+ // where _TIME_BITS=64 is defined. Abuse time_t as an alias for the correct
358
+ // suseconds_t type, as it is not an alias to the 64-bit type on 32-bit
359
+ // platforms.
360
+ typealias _Seconds = time_t
361
+ typealias _Microseconds = time_t
362
+ #else
363
+ typealias _Seconds = Int
364
+ typealias _Microseconds = Int // note: was Int32 in release/6.1
365
+ #endif
366
+ self . init ( tv_sec: _Seconds ( comps. seconds) ,
367
+ tv_usec: _Microseconds ( comps. attoseconds / 1_000_000_000_000 ) )
358
368
}
359
369
}
360
370
0 commit comments