mirror of
https://github.com/rosenpass/rosenpass.git
synced 2026-02-27 14:03:11 -08:00
13 lines
356 B
Rust
13 lines
356 B
Rust
use std::os::fd::{OwnedFd, RawFd};
|
|
|
|
/// Clone some file descriptor
|
|
///
|
|
/// If the file descriptor is invalid, an error will be raised.
|
|
pub fn claim_fd(fd: RawFd) -> anyhow::Result<OwnedFd> {
|
|
use rustix::{fd::BorrowedFd, io::dup};
|
|
|
|
// This is safe since [dup] will simply raise
|
|
let fd = unsafe { dup(BorrowedFd::borrow_raw(fd))? };
|
|
Ok(fd)
|
|
}
|