cap_primitives/rustix/fs/
reopen_impl.rs

1use crate::fs::{open_unchecked, OpenOptions};
2use crate::rustix::fs::file_path;
3use io_lifetimes::AsFilelike;
4use rustix::fs::CWD;
5use std::{fs, io};
6
7/// Implementation of `reopen`.
8pub(crate) fn reopen_impl(file: &fs::File, options: &OpenOptions) -> io::Result<fs::File> {
9    if let Some(path) = file_path(file) {
10        Ok(open_unchecked(
11            &CWD.as_filelike_view::<fs::File>(),
12            &path,
13            options,
14        )?)
15    } else {
16        Err(io::Error::new(io::ErrorKind::Other, "Couldn't reopen file"))
17    }
18}