Skip to content

Commit a7f609f

Browse files
committed
fix: weak-link Apple mknodat
1 parent cbd365c commit a7f609f

2 files changed

Lines changed: 27 additions & 6 deletions

File tree

src/backend/libc/fs/syscalls.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,13 +1208,30 @@ pub(crate) fn mknodat(
12081208
mode: Mode,
12091209
dev: Dev,
12101210
) -> io::Result<()> {
1211+
let mode = (mode.bits() | file_type.as_raw_mode()) as c::mode_t;
1212+
let dev = dev.try_into().map_err(|_e| io::Errno::PERM)?;
1213+
1214+
// Older Apple platforms lack `mknodat`.
1215+
#[cfg(apple)]
12111216
unsafe {
1212-
ret(c::mknodat(
1213-
borrowed_fd(dirfd),
1214-
c_str(path),
1215-
(mode.bits() | file_type.as_raw_mode()) as c::mode_t,
1216-
dev.try_into().map_err(|_e| io::Errno::PERM)?,
1217-
))
1217+
weak! {
1218+
fn mknodat(
1219+
c::c_int,
1220+
*const ffi::c_char,
1221+
c::mode_t,
1222+
c::dev_t
1223+
) -> c::c_int
1224+
}
1225+
// If we have `mknodat`, use it.
1226+
if let Some(libc_mknodat) = mknodat.get() {
1227+
return ret(libc_mknodat(borrowed_fd(dirfd), c_str(path), mode, dev));
1228+
}
1229+
Err(io::Errno::NOSYS)
1230+
}
1231+
1232+
#[cfg(not(apple))]
1233+
unsafe {
1234+
ret(c::mknodat(borrowed_fd(dirfd), c_str(path), mode, dev))
12181235
}
12191236
}
12201237

src/fs/at.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,11 @@ pub fn fclonefileat<Fd: AsFd, DstFd: AsFd, P: path::Arg>(
460460
/// # References
461461
/// - [POSIX]
462462
/// - [Linux]
463+
/// - [Apple]
463464
///
464465
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/mknodat.html
465466
/// [Linux]: https://man7.org/linux/man-pages/man2/mknodat.2.html
467+
/// [Apple]: https://github.com/apple-oss-distributions/xnu/blob/main/bsd/man/man2/mknodat.2
466468
#[cfg(not(any(
467469
target_os = "espidf",
468470
target_os = "horizon",
@@ -487,8 +489,10 @@ pub fn mknodat<P: path::Arg, Fd: AsFd>(
487489
///
488490
/// # References
489491
/// - [POSIX]
492+
/// - [Apple]
490493
///
491494
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/mkfifoat.html
495+
/// [Apple]: https://github.com/apple-oss-distributions/xnu/blob/main/bsd/man/man2/mkfifoat.2
492496
#[cfg(not(any(
493497
target_os = "espidf",
494498
target_os = "horizon",

0 commit comments

Comments
 (0)