mirror of
https://github.com/rust-lang/rust.git
synced 2026-06-02 06:28:20 +03:00
add helper function for target platform checks
This commit is contained in:
@@ -368,6 +368,19 @@ fn check_no_isolation(&mut self, name: &str) -> InterpResult<'tcx> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
/// Helper function used inside the shims of foreign functions to check that the target
|
||||
/// platform is `platform`. It returns an error using the `name` of the foreign function if
|
||||
/// this is not the case.
|
||||
fn check_platform(&mut self, platform: &str, name: &str) -> InterpResult<'tcx> {
|
||||
if self.eval_context_mut().tcx.sess.target.target.target_os.to_lowercase() != platform {
|
||||
throw_unsup_format!(
|
||||
"`{}` is only available in the `{}` platform",
|
||||
name,
|
||||
platform,
|
||||
)
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Sets the last error variable.
|
||||
fn set_last_error(&mut self, scalar: Scalar<Tag>) -> InterpResult<'tcx> {
|
||||
|
||||
+4
-12
@@ -347,6 +347,7 @@ fn stat(
|
||||
) -> InterpResult<'tcx, i32> {
|
||||
let this = self.eval_context_mut();
|
||||
this.check_no_isolation("stat")?;
|
||||
this.check_platform("macos", "stat")?;
|
||||
// `stat` always follows symlinks.
|
||||
this.stat_or_lstat(true, path_op, buf_op)
|
||||
}
|
||||
@@ -359,6 +360,7 @@ fn lstat(
|
||||
) -> InterpResult<'tcx, i32> {
|
||||
let this = self.eval_context_mut();
|
||||
this.check_no_isolation("lstat")?;
|
||||
this.check_platform("macos", "lstat")?;
|
||||
this.stat_or_lstat(false, path_op, buf_op)
|
||||
}
|
||||
|
||||
@@ -370,10 +372,7 @@ fn fstat(
|
||||
let this = self.eval_context_mut();
|
||||
|
||||
this.check_no_isolation("fstat")?;
|
||||
|
||||
if this.tcx.sess.target.target.target_os.to_lowercase() != "macos" {
|
||||
throw_unsup_format!("The `fstat` shim is only available for `macos` targets.")
|
||||
}
|
||||
this.check_platform("macos", "fstat")?;
|
||||
|
||||
let fd = this.read_scalar(fd_op)?.to_i32()?;
|
||||
|
||||
@@ -392,10 +391,6 @@ fn stat_or_lstat(
|
||||
) -> InterpResult<'tcx, i32> {
|
||||
let this = self.eval_context_mut();
|
||||
|
||||
if this.tcx.sess.target.target.target_os.to_lowercase() != "macos" {
|
||||
throw_unsup_format!("The `stat` and `lstat` shims are only available for `macos` targets.")
|
||||
}
|
||||
|
||||
let path_scalar = this.read_scalar(path_op)?.not_undef()?;
|
||||
let path: PathBuf = this.read_os_str_from_c_str(path_scalar)?.into();
|
||||
|
||||
@@ -417,10 +412,7 @@ fn statx(
|
||||
let this = self.eval_context_mut();
|
||||
|
||||
this.check_no_isolation("statx")?;
|
||||
|
||||
if this.tcx.sess.target.target.target_os.to_lowercase() != "linux" {
|
||||
throw_unsup_format!("The `statx` shim is only available for `linux` targets.")
|
||||
}
|
||||
this.check_platform("linux", "statx")?;
|
||||
|
||||
let statxbuf_scalar = this.read_scalar(statxbuf_op)?.not_undef()?;
|
||||
let pathname_scalar = this.read_scalar(pathname_op)?.not_undef()?;
|
||||
|
||||
Reference in New Issue
Block a user