@@ -62,32 +62,31 @@ impl FileDesc {
62
62
}
63
63
64
64
#[ 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 < ( ) > {
66
66
unsafe {
67
- let ret = libc:: ioctl ( self . fd , libc:: FIOCLEX ) ;
68
- debug_assert_eq ! ( ret , 0 ) ;
67
+ cvt ( libc:: ioctl ( self . fd , libc:: FIOCLEX ) ) ? ;
68
+ Ok ( ( ) )
69
69
}
70
70
}
71
71
#[ 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 < ( ) > {
73
73
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
- debug_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 ( ( ) )
77
77
}
78
78
}
79
79
80
- pub fn set_nonblocking ( & self , nonblocking : bool ) {
80
+ pub fn set_nonblocking ( & self , nonblocking : bool ) -> io :: Result < ( ) > {
81
81
unsafe {
82
- let previous = libc:: fcntl ( self . fd , libc:: F_GETFL ) ;
83
- debug_assert ! ( previous != -1 ) ;
82
+ let previous = cvt ( libc:: fcntl ( self . fd , libc:: F_GETFL ) ) ?;
84
83
let new = if nonblocking {
85
84
previous | libc:: O_NONBLOCK
86
85
} else {
87
86
previous & !libc:: O_NONBLOCK
88
87
} ;
89
- let ret = libc:: fcntl ( self . fd , libc:: F_SETFL , new) ;
90
- debug_assert ! ( ret != - 1 ) ;
88
+ cvt ( libc:: fcntl ( self . fd , libc:: F_SETFL , new) ) ? ;
89
+ Ok ( ( ) )
91
90
}
92
91
}
93
92
@@ -114,8 +113,8 @@ impl FileDesc {
114
113
115
114
let make_filedesc = |fd| {
116
115
let fd = FileDesc :: new ( fd) ;
117
- fd. set_cloexec ( ) ;
118
- fd
116
+ fd. set_cloexec ( ) ? ;
117
+ Ok ( fd )
119
118
} ;
120
119
static TRY_CLOEXEC : AtomicBool =
121
120
AtomicBool :: new ( !cfg ! ( target_os = "android" ) ) ;
@@ -127,7 +126,7 @@ impl FileDesc {
127
126
// though it reported doing so on F_DUPFD_CLOEXEC.
128
127
Ok ( fd) => {
129
128
return Ok ( if cfg ! ( target_os = "linux" ) {
130
- make_filedesc ( fd)
129
+ make_filedesc ( fd) ?
131
130
} else {
132
131
FileDesc :: new ( fd)
133
132
} )
@@ -138,7 +137,7 @@ impl FileDesc {
138
137
Err ( e) => return Err ( e) ,
139
138
}
140
139
}
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)
142
141
}
143
142
}
144
143
0 commit comments