Auto merge of #3573 - RalfJung:fs-cfg, r=RalfJung

unix/fs: a bit of cleanup around host-specific code
This commit is contained in:
bors 2024-05-05 16:51:27 +00:00
commit a418b2dc70

View file

@ -137,37 +137,28 @@ trait EvalContextExtPrivate<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx
&mut self,
file_type: std::io::Result<FileType>,
) -> InterpResult<'tcx, i32> {
#[cfg(unix)]
use std::os::unix::fs::FileTypeExt;
let this = self.eval_context_mut();
match file_type {
Ok(file_type) => {
if file_type.is_dir() {
Ok(this.eval_libc("DT_DIR").to_u8()?.into())
} else if file_type.is_file() {
Ok(this.eval_libc("DT_REG").to_u8()?.into())
} else if file_type.is_symlink() {
Ok(this.eval_libc("DT_LNK").to_u8()?.into())
} else {
match () {
_ if file_type.is_dir() => Ok(this.eval_libc("DT_DIR").to_u8()?.into()),
_ if file_type.is_file() => Ok(this.eval_libc("DT_REG").to_u8()?.into()),
_ if file_type.is_symlink() => Ok(this.eval_libc("DT_LNK").to_u8()?.into()),
// Certain file types are only supported when the host is a Unix system.
// (i.e. devices and sockets) If it is, check those cases, if not, fall back to
// DT_UNKNOWN sooner.
#[cfg(unix)]
{
use std::os::unix::fs::FileTypeExt;
if file_type.is_block_device() {
Ok(this.eval_libc("DT_BLK").to_u8()?.into())
} else if file_type.is_char_device() {
Ok(this.eval_libc("DT_CHR").to_u8()?.into())
} else if file_type.is_fifo() {
Ok(this.eval_libc("DT_FIFO").to_u8()?.into())
} else if file_type.is_socket() {
Ok(this.eval_libc("DT_SOCK").to_u8()?.into())
} else {
Ok(this.eval_libc("DT_UNKNOWN").to_u8()?.into())
}
}
#[cfg(not(unix))]
Ok(this.eval_libc("DT_UNKNOWN").to_u8()?.into())
_ if file_type.is_block_device() =>
Ok(this.eval_libc("DT_BLK").to_u8()?.into()),
#[cfg(unix)]
_ if file_type.is_char_device() => Ok(this.eval_libc("DT_CHR").to_u8()?.into()),
#[cfg(unix)]
_ if file_type.is_fifo() => Ok(this.eval_libc("DT_FIFO").to_u8()?.into()),
#[cfg(unix)]
_ if file_type.is_socket() => Ok(this.eval_libc("DT_SOCK").to_u8()?.into()),
// Fallback
_ => Ok(this.eval_libc("DT_UNKNOWN").to_u8()?.into()),
}
}
Err(e) =>
@ -1314,7 +1305,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
}
}
#[cfg_attr(not(unix), allow(unused))]
fn isatty(
&mut self,
miri_fd: &OpTy<'tcx, Provenance>,
@ -1467,8 +1457,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
#[cfg(unix)]
{
use std::os::unix::fs::OpenOptionsExt;
fopts.mode(0o600);
// Do not allow others to read or modify this file.
fopts.mode(0o600);
fopts.custom_flags(libc::O_EXCL);
}
#[cfg(windows)]