From: Ian Jackson Date: Sun, 25 Feb 2024 01:55:59 +0000 (+0000) Subject: nix: Provide a compat version of write for 0.28 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=a58e13658ef3984ac142a8ccc357b17c9bebae9a;p=hippotat.git nix: Provide a compat version of write for 0.28 Signed-off-by: Ian Jackson --- diff --git a/server/daemon.rs b/server/daemon.rs index a45fccb..45a8f81 100644 --- a/server/daemon.rs +++ b/server/daemon.rs @@ -95,7 +95,7 @@ unsafe fn mdup2(oldfd: RawFd, newfd: RawFd, what: &str) { } unsafe fn write_status(st_wfd: RawFd, estatus: u8) { - match write(st_wfd, slice::from_ref(&estatus)) { + match compat::write(st_wfd, slice::from_ref(&estatus)) { Ok(1) => {} Ok(_) => crashm("write child startup exit status: short write"), Err(e) => crashe("write child startup exit status", e), diff --git a/src/compat.rs b/src/compat.rs index 75d478d..f02d981 100644 --- a/src/compat.rs +++ b/src/compat.rs @@ -18,3 +18,20 @@ pub unsafe fn writev(fd: c_int, iov: &[IoSlice]) -> nix::Result { iov, ) } + +/// Version of [`nix::unistd::write`] with a fixed type for the fd +// +/// * nix <=0.27 has `fd: c_int` +/// * nix >=0.28 has `fd: impl AsFd` +pub unsafe fn write(fd: c_int, buf: &[u8]) -> nix::Result { + nix::unistd::write( + { cfg_if! { + if #[cfg(nix_ge_0_28)] { + BorrowedFd::borrow_raw(fd) + } else { + fd + } + }}, + buf, + ) +}