@@ -62,32 +62,31 @@ impl FileDesc {
6262 }
6363
6464 #[ cfg( not( any( target_env = "newlib" , target_os = "solaris" , target_os = "emscripten" ) ) ) ]
65- pub fn set_cloexec ( & self ) {
65+ pub fn set_cloexec ( & self ) -> io :: Result < ( ) > {
6666 unsafe {
67- let ret = libc:: ioctl ( self . fd , libc:: FIOCLEX ) ;
68- assert_eq ! ( ret , 0 ) ;
67+ cvt ( libc:: ioctl ( self . fd , libc:: FIOCLEX ) ) ? ;
68+ Ok ( ( ) )
6969 }
7070 }
7171 #[ cfg( any( target_env = "newlib" , target_os = "solaris" , target_os = "emscripten" ) ) ]
72- pub fn set_cloexec ( & self ) {
72+ pub fn set_cloexec ( & self ) -> io :: Result < ( ) > {
7373 unsafe {
74- let previous = libc:: fcntl ( self . fd , libc:: F_GETFD ) ;
75- let ret = libc:: fcntl ( self . fd , libc:: F_SETFD , previous | libc:: FD_CLOEXEC ) ;
76- assert_eq ! ( ret , 0 ) ;
74+ let previous = cvt ( libc:: fcntl ( self . fd , libc:: F_GETFD ) ) ? ;
75+ cvt ( libc:: fcntl ( self . fd , libc:: F_SETFD , previous | libc:: FD_CLOEXEC ) ) ? ;
76+ Ok ( ( ) )
7777 }
7878 }
7979
80- pub fn set_nonblocking ( & self , nonblocking : bool ) {
80+ pub fn set_nonblocking ( & self , nonblocking : bool ) -> io :: Result < ( ) > {
8181 unsafe {
82- let previous = libc:: fcntl ( self . fd , libc:: F_GETFL ) ;
83- assert ! ( previous != -1 ) ;
82+ let previous = cvt ( libc:: fcntl ( self . fd , libc:: F_GETFL ) ) ?;
8483 let new = if nonblocking {
8584 previous | libc:: O_NONBLOCK
8685 } else {
8786 previous & !libc:: O_NONBLOCK
8887 } ;
89- let ret = libc:: fcntl ( self . fd , libc:: F_SETFL , new) ;
90- assert ! ( ret != - 1 ) ;
88+ cvt ( libc:: fcntl ( self . fd , libc:: F_SETFL , new) ) ? ;
89+ Ok ( ( ) )
9190 }
9291 }
9392
@@ -114,8 +113,8 @@ impl FileDesc {
114113
115114 let make_filedesc = |fd| {
116115 let fd = FileDesc :: new ( fd) ;
117- fd. set_cloexec ( ) ;
118- fd
116+ fd. set_cloexec ( ) ? ;
117+ Ok ( fd )
119118 } ;
120119 static TRY_CLOEXEC : AtomicBool =
121120 AtomicBool :: new ( !cfg ! ( target_os = "android" ) ) ;
@@ -127,7 +126,7 @@ impl FileDesc {
127126 // though it reported doing so on F_DUPFD_CLOEXEC.
128127 Ok ( fd) => {
129128 return Ok ( if cfg ! ( target_os = "linux" ) {
130- make_filedesc ( fd)
129+ make_filedesc ( fd) ?
131130 } else {
132131 FileDesc :: new ( fd)
133132 } )
@@ -138,7 +137,7 @@ impl FileDesc {
138137 Err ( e) => return Err ( e) ,
139138 }
140139 }
141- cvt ( unsafe { libc:: fcntl ( fd, libc:: F_DUPFD , 0 ) } ) . map ( make_filedesc)
140+ cvt ( unsafe { libc:: fcntl ( fd, libc:: F_DUPFD , 0 ) } ) . and_then ( make_filedesc)
142141 }
143142}
144143
0 commit comments