diff --git a/src/backend/libc/fs/syscalls.rs b/src/backend/libc/fs/syscalls.rs index 71bc8b0ab..255916659 100644 --- a/src/backend/libc/fs/syscalls.rs +++ b/src/backend/libc/fs/syscalls.rs @@ -52,7 +52,6 @@ use crate::fs::StatFs; #[cfg(not(any(target_os = "espidf", target_os = "vita")))] use crate::fs::Timestamps; #[cfg(not(any( - apple, target_os = "espidf", target_os = "redox", target_os = "vita", @@ -1196,7 +1195,6 @@ pub(crate) fn chownat( } #[cfg(not(any( - apple, target_os = "espidf", target_os = "horizon", target_os = "redox", @@ -1210,13 +1208,27 @@ pub(crate) fn mknodat( mode: Mode, dev: Dev, ) -> io::Result<()> { + let mode = (mode.bits() | file_type.as_raw_mode()) as c::mode_t; + let dev = dev.try_into().map_err(|_e| io::Errno::PERM)?; + + // Older Apple platforms lack `mknodat`. + #[cfg(apple)] unsafe { - ret(c::mknodat( - borrowed_fd(dirfd), - c_str(path), - (mode.bits() | file_type.as_raw_mode()) as c::mode_t, - dev.try_into().map_err(|_e| io::Errno::PERM)?, - )) + weak! { + fn mknodat( + c::c_int, + *const ffi::c_char, + c::mode_t, + c::dev_t + ) -> c::c_int + } + let libc_mknodat = mknodat.get().ok_or(io::Errno::NOSYS)?; + ret(libc_mknodat(borrowed_fd(dirfd), c_str(path), mode, dev)) + } + + #[cfg(not(apple))] + unsafe { + ret(c::mknodat(borrowed_fd(dirfd), c_str(path), mode, dev)) } } diff --git a/src/fs/at.rs b/src/fs/at.rs index f35ce5aca..d3b00eaff 100644 --- a/src/fs/at.rs +++ b/src/fs/at.rs @@ -20,7 +20,7 @@ use crate::fs::CloneFlags; use crate::fs::RenameFlags; #[cfg(not(target_os = "espidf"))] use crate::fs::Stat; -#[cfg(not(any(apple, target_os = "espidf", target_os = "vita", target_os = "wasi")))] +#[cfg(not(any(target_os = "espidf", target_os = "vita", target_os = "wasi")))] use crate::fs::{Dev, FileType}; #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] use crate::fs::{Gid, Uid}; @@ -460,11 +460,12 @@ pub fn fclonefileat( /// # References /// - [POSIX] /// - [Linux] +/// - [Apple] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/mknodat.html /// [Linux]: https://man7.org/linux/man-pages/man2/mknodat.2.html +/// [Apple]: https://github.com/apple-oss-distributions/xnu/blob/main/bsd/man/man2/mknodat.2 #[cfg(not(any( - apple, target_os = "espidf", target_os = "horizon", target_os = "vita", @@ -488,10 +489,11 @@ pub fn mknodat( /// /// # References /// - [POSIX] +/// - [Apple] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/mkfifoat.html +/// [Apple]: https://github.com/apple-oss-distributions/xnu/blob/main/bsd/man/man2/mkfifoat.2 #[cfg(not(any( - apple, target_os = "espidf", target_os = "horizon", target_os = "vita",