File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -138,15 +138,15 @@ cfg_if! {
138
138
}
139
139
140
140
// SAFETY: path must be null terminated, FD must be manually closed.
141
- pub unsafe fn open_readonly ( path : & str ) -> Option < libc:: c_int > {
141
+ pub unsafe fn open_readonly ( path : & str ) -> Result < libc:: c_int , Error > {
142
142
debug_assert ! ( path. as_bytes( ) . last( ) == Some ( & 0 ) ) ;
143
- let fd = open ( path. as_ptr ( ) as * mut _ , libc:: O_RDONLY | libc:: O_CLOEXEC ) ;
143
+ let fd = open ( path. as_ptr ( ) as * const _ , libc:: O_RDONLY | libc:: O_CLOEXEC ) ;
144
144
if fd < 0 {
145
- return None ;
145
+ return Err ( last_os_error ( ) ) ;
146
146
}
147
147
// O_CLOEXEC works on all Unix targets except for older Linux kernels (pre
148
148
// 2.6.23), so we also use an ioctl to make sure FD_CLOEXEC is set.
149
149
#[ cfg( target_os = "linux" ) ]
150
150
libc:: ioctl ( fd, libc:: FIOCLEX ) ;
151
- Some ( fd)
151
+ Ok ( fd)
152
152
}
You can’t perform that action at this time.
0 commit comments