Skip to content

Commit c7e97e2

Browse files
simplify field writing
1 parent 5f54876 commit c7e97e2

File tree

1 file changed

+6
-26
lines changed

1 file changed

+6
-26
lines changed

src/shims/unix/fs.rs

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -995,36 +995,16 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
995995

996996
// Write common fields
997997
let ino_name =
998-
if this.tcx.sess.target.os == "freebsd" { "d_fileno" } else { "d_ino " };
998+
if this.tcx.sess.target.os == "freebsd" { "d_fileno" } else { "d_ino" };
999+
let off_name =
1000+
if this.tcx.sess.target.os == "macos" { "d_seekoff" } else { "d_off" };
9991001
this.write_int_fields_named(
1000-
&[(ino_name, ino.into()), ("d_reclen", size.into())],
1002+
&[(ino_name, ino.into()), (off_name, 0), ("d_reclen", size.into())],
10011003
entry_place,
10021004
)?;
10031005

1004-
// Hanlde os specific fields
1005-
match &*this.tcx.sess.target.os {
1006-
"macos" => {
1007-
this.write_int_fields_named(
1008-
&[
1009-
("d_seekoff", 0),
1010-
("d_namlen", (name_len - 1).into()), // Zero Byte not included
1011-
],
1012-
entry_place,
1013-
)?;
1014-
}
1015-
"freebsd" => {
1016-
this.write_int_fields_named(
1017-
&[
1018-
("d_off", 0),
1019-
("d_namlen", (name_len - 1).into()), // Zero Byte not included
1020-
],
1021-
entry_place,
1022-
)?;
1023-
}
1024-
"linux" | "solaris" | "illumos" => {
1025-
this.write_int_fields_named(&[("d_off", 0)], entry_place)?;
1026-
}
1027-
_ => unreachable!(),
1006+
if let Some(d_namlen) = this.try_project_field_named(entry_place, "d_namlen")? {
1007+
this.write_int(name_len.strict_sub(1), &d_namlen)?;
10281008
}
10291009

10301010
let file_type = this.file_type_to_d_type(dir_entry.file_type())?;

0 commit comments

Comments
 (0)