@@ -334,7 +334,7 @@ extension timespec {
334334 @available ( SwiftStdlib 5 . 7 , * )
335335 public init ( _ duration: Duration ) {
336336 let comps = duration. components
337- self . init ( tv_sec: Int ( comps. seconds) ,
337+ self . init ( tv_sec: time_t ( comps. seconds) ,
338338 tv_nsec: Int ( comps. attoseconds / 1_000_000_000 ) )
339339 }
340340}
@@ -352,9 +352,19 @@ extension timeval {
352352 @available ( SwiftStdlib 5 . 7 , * )
353353 public init ( _ duration: Duration ) {
354354 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 ) )
358368 }
359369}
360370
0 commit comments