Skip to content

Commit 001d2f7

Browse files
authored
Merge pull request #4754 from RalfJung/ftruncate-non-file-backed
ftruncate: return proper error code for non-file-backed FDs
2 parents eb01df9 + 3f48189 commit 001d2f7

File tree

1 file changed

+7
-7
lines changed
  • src/tools/miri/src/shims/unix

1 file changed

+7
-7
lines changed

src/tools/miri/src/shims/unix/fs.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,10 +1157,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
11571157
return this.set_last_error_and_return_i32(LibcError("EBADF"));
11581158
};
11591159

1160-
// FIXME: Support ftruncate64 for all FDs
1161-
let file = fd.downcast::<FileHandle>().ok_or_else(|| {
1162-
err_unsup_format!("`ftruncate64` is only supported on file-backed file descriptors")
1163-
})?;
1160+
let Some(file) = fd.downcast::<FileHandle>() else {
1161+
// The docs say that EINVAL is returned when the FD "does not reference a regular file
1162+
// or a POSIX shared memory object" (and we don't support shmem objects).
1163+
return interp_ok(this.eval_libc("EINVAL"));
1164+
};
11641165

11651166
if file.writable {
11661167
if let Ok(length) = length.try_into() {
@@ -1202,10 +1203,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
12021203
let Some(fd) = this.machine.fds.get(fd_num) else {
12031204
return interp_ok(this.eval_libc("EBADF"));
12041205
};
1205-
let file = match fd.downcast::<FileHandle>() {
1206-
Some(file_handle) => file_handle,
1206+
let Some(file) = fd.downcast::<FileHandle>() else {
12071207
// Man page specifies to return ENODEV if `fd` is not a regular file.
1208-
None => return interp_ok(this.eval_libc("ENODEV")),
1208+
return interp_ok(this.eval_libc("ENODEV"));
12091209
};
12101210

12111211
if !file.writable {

0 commit comments

Comments
 (0)