From 53e072f2207747e8b60dcbb77b763c1598cfb192 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 5 Oct 2021 14:11:49 -0700 Subject: [PATCH] Fix compilation on WASI, which doesn't yet support `dup`. --- library/std/src/os/fd/owned.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/library/std/src/os/fd/owned.rs b/library/std/src/os/fd/owned.rs index 597e050b00d5..0b6588db92c8 100644 --- a/library/std/src/os/fd/owned.rs +++ b/library/std/src/os/fd/owned.rs @@ -8,6 +8,7 @@ use crate::fmt; use crate::fs; use crate::marker::PhantomData; use crate::mem::forget; +#[cfg(not(target_os = "wasi"))] use crate::sys::cvt; use crate::sys_common::{AsInner, FromInner, IntoInner}; @@ -71,6 +72,7 @@ impl BorrowedFd<'_> { impl OwnedFd { /// Creates a new `OwnedFd` instance that shares the same underlying file handle /// as the existing `OwnedFd` instance. + #[cfg(not(target_os = "wasi"))] pub fn try_clone(&self) -> crate::io::Result { // We want to atomically duplicate this file descriptor and set the // CLOEXEC flag, and currently that's done via F_DUPFD_CLOEXEC. This @@ -88,6 +90,14 @@ impl OwnedFd { let fd = cvt(unsafe { libc::fcntl(self.as_raw_fd(), cmd, 0) })?; Ok(unsafe { Self::from_raw_fd(fd) }) } + + #[cfg(target_os = "wasi")] + pub fn try_clone(&self) -> crate::io::Result { + Err(crate::io::Error::new_const( + crate::io::ErrorKind::Unsupported, + &"operation not supported on WASI yet", + )) + } } #[unstable(feature = "io_safety", issue = "87074")]