Skip to content

Commit

Permalink
glibc wrapper only available on recent glibc releases
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen committed Oct 23, 2024
1 parent dc3b011 commit 4c1f57d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4024,7 +4024,14 @@ pub fn close_range<F: std::os::fd::AsFd>(fdbegin: F, fdlast: F, flags: CloseRang

let raw = unsafe {
Errno::clear();
libc::close_range(fdbegin.as_fd().as_raw_fd() as u32, fdlast.as_fd().as_raw_fd() as u32, flags.bits() as i32)

cfg_if! {
if #[cfg(all(target_os = "linux", target_env = "gnu"))] {
libc::syscall(libc::SYS_close_range, fdbegin.as_fd().as_raw_fd() as u32, fdlast.as_fd().as_raw_fd() as u32, flags.bits() as i32)
} else {
libc::close_range(fdbegin.as_fd().as_raw_fd() as u32, fdlast.as_fd().as_raw_fd() as u32, flags.bits() as i32)
}
}
};
if raw == -1 {
if Errno::last_raw() == 0 {
Expand All @@ -4033,6 +4040,8 @@ pub fn close_range<F: std::os::fd::AsFd>(fdbegin: F, fdlast: F, flags: CloseRang
Err(Errno::last())
}
} else {
#[cfg(all(target_os = "linux", target_env = "gnu", target_pointer_width = "64"))]
let raw = raw as i32;
Ok(Some(raw))
}

Expand Down
1 change: 1 addition & 0 deletions test/test_unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,7 @@ fn test_group_from() {
all(target_os = "linux", target_env = "gnu"),
target_os = "freebsd"
))]
#[cfg_attr(qemu, ignore)]
fn test_close_range() {
use tempfile::NamedTempFile;
const CONTENTS: &[u8] = b"abcdef123456";
Expand Down

0 comments on commit 4c1f57d

Please sign in to comment.