File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1872,7 +1872,12 @@ fn file_time_to_timespec(time: Option<SystemTime>) -> io::Result<libc::timespec>
18721872 io:: ErrorKind :: InvalidInput ,
18731873 "timestamp is too small to set as a file time" ,
18741874 ) ) ,
1875- None => Ok ( libc:: timespec { tv_sec : 0 , tv_nsec : libc:: UTIME_OMIT as _ } ) ,
1875+ None => Ok ( {
1876+ let mut ts = libc:: timespec:: default ( ) ;
1877+ ts. tv_sec = 0 ;
1878+ ts. tv_nsec = libc:: UTIME_OMIT as _ ;
1879+ ts
1880+ } ) ,
18761881 }
18771882}
18781883
Original file line number Diff line number Diff line change 1+ use core:: mem;
12use core:: num:: niche_types:: Nanoseconds ;
23
34use crate :: io;
@@ -6,8 +7,12 @@ use crate::time::Duration;
67const NSEC_PER_SEC : u64 = 1_000_000_000 ;
78
89#[ allow( dead_code) ] // Used for pthread condvar timeouts
9- pub const TIMESPEC_MAX : libc:: timespec =
10- libc:: timespec { tv_sec : <libc:: time_t >:: MAX , tv_nsec : 1_000_000_000 - 1 } ;
10+ pub const TIMESPEC_MAX : libc:: timespec = {
11+ let mut ts = unsafe { mem:: zeroed :: < libc:: timespec > ( ) } ;
12+ ts. tv_sec = <libc:: time_t >:: MAX ;
13+ ts. tv_nsec = 1_000_000_000 - 1 ;
14+ ts
15+ } ;
1116
1217// This additional constant is only used when calling
1318// `libc::pthread_cond_timedwait`.
@@ -164,9 +169,11 @@ impl Timespec {
164169
165170 #[ allow( dead_code) ]
166171 pub fn to_timespec ( & self ) -> Option < libc:: timespec > {
167- Some ( libc:: timespec {
168- tv_sec : self . tv_sec . try_into ( ) . ok ( ) ?,
169- tv_nsec : self . tv_nsec . as_inner ( ) . try_into ( ) . ok ( ) ?,
172+ Some ( {
173+ let mut ts = libc:: timespec:: default ( ) ;
174+ ts. tv_sec = self . tv_sec . try_into ( ) . ok ( ) ?;
175+ ts. tv_nsec = self . tv_nsec . as_inner ( ) . try_into ( ) . ok ( ) ?;
176+ ts
170177 } )
171178 }
172179
Original file line number Diff line number Diff line change @@ -570,10 +570,10 @@ pub fn sleep(dur: Duration) {
570570 // nanosleep will fill in `ts` with the remaining time.
571571 unsafe {
572572 while secs > 0 || nsecs > 0 {
573- let mut ts = libc:: timespec {
574- tv_sec : cmp:: min ( libc:: time_t:: MAX as u64 , secs) as libc:: time_t ,
575- tv_nsec : nsecs,
576- } ;
573+ let mut ts = libc:: timespec:: default ( ) ;
574+ ts . tv_sec = cmp:: min ( libc:: time_t:: MAX as u64 , secs) as libc:: time_t ;
575+ ts . tv_nsec = nsecs;
576+
577577 secs -= ts. tv_sec as u64 ;
578578 let ts_ptr = & raw mut ts;
579579 let r = nanosleep ( ts_ptr, ts_ptr) ;
You can’t perform that action at this time.
0 commit comments