Skip to content

Commit

Permalink
Add RHEL 5 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
josephlr committed Aug 5, 2019
1 parent 9d04e3a commit 6a45c49
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/util_libc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,13 @@ cfg_if! {
// SAFETY: path must be null terminated, FD must be manually closed.
pub unsafe fn open_readonly(path: &str) -> Option<libc::c_int> {
debug_assert!(path.as_bytes().last() == Some(&0));
// We don't care about Linux OSes too old to support O_CLOEXEC.
let fd = open(path.as_ptr() as *mut _, libc::O_RDONLY | libc::O_CLOEXEC);
if fd < 0 {
return None;
}
// O_CLOEXEC works on all Unix targets except for older Linux kernels (pre
// 2.6.23), so we also use an ioctl to make sure FD_CLOEXEC is set.
#[cfg(target_os = "linux")]
libc::ioctl(self.fd, libc::FIOCLEX);
Some(fd)
}

0 comments on commit 6a45c49

Please sign in to comment.