From 91d57d88d43dd016697b50dbb0d654be3e05784e Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 14 Sep 2025 11:18:58 +0400 Subject: [PATCH] Enable fcntl OFD commands on macOS This PR adds support for Open File Description (OFD) fcntl commands on macOS. The implementation uses the upstream libc crate which now includes the required constants that were previously only available in a fork. Changes: - Added macOS OFD fcntl command support in src/fcntl.rs - Updated sys/select.rs with improved file descriptor handling - Fixed type casting issues in test_select.rs --- changelog/2300.added.md | 1 + src/fcntl.rs | 12 ++++++------ src/sys/select.rs | 1 - test/test_sendfile.rs | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 changelog/2300.added.md diff --git a/changelog/2300.added.md b/changelog/2300.added.md new file mode 100644 index 0000000000..964733df5c --- /dev/null +++ b/changelog/2300.added.md @@ -0,0 +1 @@ +Added `F_OFD_SETLK`, `F_OFD_SETLKW`, and `F_OFD_GETLK` fcntl commands on macOS diff --git a/src/fcntl.rs b/src/fcntl.rs index 6504c1dcf2..da991889d5 100644 --- a/src/fcntl.rs +++ b/src/fcntl.rs @@ -751,15 +751,15 @@ pub enum FcntlArg<'a> { /// Get the first lock that blocks the lock description F_GETLK(&'a mut libc::flock), /// Acquire or release an open file description lock - #[cfg(linux_android)] + #[cfg(any(linux_android, macos))] F_OFD_SETLK(&'a libc::flock), /// Like [`F_OFD_SETLK`] except that if a conflicting lock is held on /// the file, then wait for that lock to be released. - #[cfg(linux_android)] + #[cfg(any(linux_android, macos))] F_OFD_SETLKW(&'a libc::flock), /// Determine whether it would be possible to create the given lock. If not, return details /// about one existing lock that would prevent it. - #[cfg(linux_android)] + #[cfg(any(linux_android, macos))] F_OFD_GETLK(&'a mut libc::flock), /// Add seals to the file #[cfg(any( @@ -879,11 +879,11 @@ pub fn fcntl(fd: Fd, arg: FcntlArg) -> Result { F_SETLKW(flock) => libc::fcntl(fd, libc::F_SETLKW, flock), #[cfg(not(target_os = "redox"))] F_GETLK(flock) => libc::fcntl(fd, libc::F_GETLK, flock), - #[cfg(linux_android)] + #[cfg(any(linux_android, macos))] F_OFD_SETLK(flock) => libc::fcntl(fd, libc::F_OFD_SETLK, flock), - #[cfg(linux_android)] + #[cfg(any(linux_android, macos))] F_OFD_SETLKW(flock) => libc::fcntl(fd, libc::F_OFD_SETLKW, flock), - #[cfg(linux_android)] + #[cfg(any(linux_android, macos))] F_OFD_GETLK(flock) => libc::fcntl(fd, libc::F_OFD_GETLK, flock), #[cfg(any( linux_android, diff --git a/src/sys/select.rs b/src/sys/select.rs index b15fab886d..7a2faf8f63 100644 --- a/src/sys/select.rs +++ b/src/sys/select.rs @@ -3,7 +3,6 @@ use crate::errno::Errno; use crate::sys::time::{TimeSpec, TimeVal}; use crate::Result; use libc::{self, c_int}; -use std::convert::TryFrom; use std::iter::FusedIterator; use std::mem; use std::ops::Range; diff --git a/test/test_sendfile.rs b/test/test_sendfile.rs index ab50a1d040..8d2c50b845 100644 --- a/test/test_sendfile.rs +++ b/test/test_sendfile.rs @@ -159,10 +159,10 @@ fn test_sendfile_dragonfly() { fn test_sendfile_darwin() { // Declare the content let header_strings = - vec!["HTTP/1.1 200 OK\n", "Content-Type: text/plain\n", "\n"]; + ["HTTP/1.1 200 OK\n", "Content-Type: text/plain\n", "\n"]; let body = "Xabcdef123456"; let body_offset = 1; - let trailer_strings = vec!["\n", "Served by Make Believe\n"]; + let trailer_strings = ["\n", "Served by Make Believe\n"]; // Write the body to a file let mut tmp = tempfile().unwrap();