Skip to content

Commit a481b8f

Browse files
committed
partially implement 'set_last_error_from_io_error' for Windows
1 parent c706f50 commit a481b8f

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/helpers.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
7171
.not_undef()
7272
}
7373

74+
/// Helper function to get a `windows` constant as a `Scalar`.
75+
fn eval_windows(&mut self, name: &str) -> InterpResult<'tcx, Scalar<Tag>> {
76+
self.eval_context_mut()
77+
.eval_path_scalar(&["std", "sys", "windows", "c", name])?
78+
.not_undef()
79+
}
80+
7481
/// Helper function to get a `libc` constant as an `i32`.
7582
fn eval_libc_i32(&mut self, name: &str) -> InterpResult<'tcx, i32> {
7683
// TODO: Cache the result.
@@ -428,11 +435,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
428435
}
429436
})?
430437
} else {
431-
// FIXME: we have to implement the Windows equivalent of this.
432-
throw_unsup_format!(
433-
"setting the last OS error from an io::Error is unsupported for {}.",
434-
target.target_os
435-
)
438+
// FIXME: we have to finish implementing the Windows equivalent of this.
439+
this.eval_windows(match e.kind() {
440+
NotFound => "ERROR_FILE_NOT_FOUND",
441+
_ => throw_unsup_format!(
442+
"setting the last OS error from an io::Error is yet unsupported for {}.",
443+
target.target_os
444+
)
445+
})?
436446
};
437447
this.set_last_error(last_error)
438448
}

0 commit comments

Comments
 (0)