Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove libstd dependancy for Opening and Reading files #58

Merged
merged 11 commits into from
Aug 6, 2019
Prev Previous commit
Next Next commit
Add RHEL 5 compat
  • Loading branch information
josephlr committed Aug 5, 2019
commit 6a45c49c259544ce34c745d23b01886b559b7e4f
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);
newpavlov marked this conversation as resolved.
Show resolved Hide resolved
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)
}