From 4c1f57dcd6e697bb6c2940d7f49dc6861cff3581 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Tue, 22 Oct 2024 23:40:22 +0100 Subject: [PATCH] glibc wrapper only available on recent glibc releases --- src/unistd.rs | 11 ++++++++++- test/test_unistd.rs | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/unistd.rs b/src/unistd.rs index 0e33dda1d1..b414866cdd 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -4024,7 +4024,14 @@ pub fn close_range(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 { @@ -4033,6 +4040,8 @@ pub fn close_range(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)) } diff --git a/test/test_unistd.rs b/test/test_unistd.rs index 6ed4af5dea..61dbc812e0 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -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";