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