From 01ad8ac2bc4c74c5432134ab06632ab89903d0dd Mon Sep 17 00:00:00 2001 From: Yuki Sireneva Date: Wed, 18 Dec 2024 21:06:03 +0300 Subject: [PATCH] Use `libc::setdomainname` where possible Use weak `setdomainname` only for android; remove this special case once [libc#4212] is merged. [libc#4212]: https://github.com/rust-lang/libc/pull/4212 --- src/backend/libc/system/syscalls.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/backend/libc/system/syscalls.rs b/src/backend/libc/system/syscalls.rs index 8807de983..0c5b0f7d5 100644 --- a/src/backend/libc/system/syscalls.rs +++ b/src/backend/libc/system/syscalls.rs @@ -64,6 +64,7 @@ pub(crate) fn sethostname(name: &[u8]) -> io::Result<()> { } #[cfg(not(any( + target_os = "android", target_os = "emscripten", target_os = "espidf", target_os = "haiku", @@ -71,6 +72,17 @@ pub(crate) fn sethostname(name: &[u8]) -> io::Result<()> { target_os = "vita", target_os = "wasi" )))] +pub(crate) fn setdomainname(name: &[u8]) -> io::Result<()> { + unsafe { + ret(c::setdomainname( + name.as_ptr().cast(), + name.len().try_into().map_err(|_| io::Errno::INVAL)?, + )) + } +} + +// https://github.com/rust-lang/libc/pull/4212 +#[cfg(target_os = "android")] pub(crate) fn setdomainname(name: &[u8]) -> io::Result<()> { syscall! { fn setdomainname(