diff options
| author | Dan Gohman <dev@sunfishcode.online> | 2021-09-09 14:05:10 -0700 |
|---|---|---|
| committer | Dan Gohman <dev@sunfishcode.online> | 2021-09-09 14:16:28 -0700 |
| commit | 18c14add399c35153883f8b84a2e11a7c22f6721 (patch) | |
| tree | cc11eb72236251b79e7cb576f24a34b54c969d21 /library/std/src/sys/unix/fd.rs | |
| parent | 497ee321af3b8496eaccd7af7b437f18bab81abf (diff) | |
| download | rust-18c14add399c35153883f8b84a2e11a7c22f6721.tar.gz rust-18c14add399c35153883f8b84a2e11a7c22f6721.zip | |
Add a `try_clone()` function to `OwnedFd`.
As suggested in #88564. This adds a `try_clone()` to `OwnedFd` by refactoring the code out of the existing `File`/`Socket` code.
Diffstat (limited to 'library/std/src/sys/unix/fd.rs')
| -rw-r--r-- | library/std/src/sys/unix/fd.rs | 17 |
1 files changed, 2 insertions, 15 deletions
diff --git a/library/std/src/sys/unix/fd.rs b/library/std/src/sys/unix/fd.rs index 0956726084e..3c2b36fe691 100644 --- a/library/std/src/sys/unix/fd.rs +++ b/library/std/src/sys/unix/fd.rs @@ -266,22 +266,9 @@ impl FileDesc { } } + #[inline] pub fn duplicate(&self) -> io::Result<FileDesc> { - // We want to atomically duplicate this file descriptor and set the - // CLOEXEC flag, and currently that's done via F_DUPFD_CLOEXEC. This - // is a POSIX flag that was added to Linux in 2.6.24. - #[cfg(not(target_os = "espidf"))] - let cmd = libc::F_DUPFD_CLOEXEC; - - // For ESP-IDF, F_DUPFD is used instead, because the CLOEXEC semantics - // will never be supported, as this is a bare metal framework with - // no capabilities for multi-process execution. While F_DUPFD is also - // not supported yet, it might be (currently it returns ENOSYS). - #[cfg(target_os = "espidf")] - let cmd = libc::F_DUPFD; - - let fd = cvt(unsafe { libc::fcntl(self.as_raw_fd(), cmd, 0) })?; - Ok(unsafe { FileDesc::from_raw_fd(fd) }) + Ok(Self(self.0.try_clone()?)) } } |
