]> git.lizzy.rs Git - rust.git/commitdiff
Add lstat shim for macos
authorChristian Poveda <git@christianpoveda.xyz>
Tue, 7 Jan 2020 16:29:25 +0000 (11:29 -0500)
committerChristian Poveda <git@christianpoveda.xyz>
Tue, 7 Jan 2020 17:26:23 +0000 (12:26 -0500)
src/shims/foreign_items.rs
src/shims/fs.rs

index 6a2f42f8321507cf7e61c2fd1d81a2ea96f0dc4d..f3baebad143b3664e04a31cd98286062e6348b7d 100644 (file)
@@ -504,6 +504,11 @@ fn emulate_foreign_item(
                 this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;
             }
 
+            "lstat$INODE64" => {
+                let result = this.lstat(args[0], args[1])?;
+                this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;
+            }
+
             "clock_gettime" => {
                 let result = this.clock_gettime(args[0], args[1])?;
                 this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;
index c5b753f3b6a245ffe8ab98ed4f0333a0117555a0..3927f0e649198234eab6101deb33f32d7cf0fa44 100644 (file)
@@ -312,6 +312,29 @@ fn stat(
         buf_op: OpTy<'tcx, Tag>,
     ) -> InterpResult<'tcx, i32> {
         let this = self.eval_context_mut();
+        this.check_no_isolation("stat")?;
+        // `stat` always follows symlinks.
+        this.stat_or_lstat(true, path_op, buf_op)
+    }
+
+    // `lstat` is used to get symlink metadata.
+    fn lstat(
+        &mut self,
+        path_op: OpTy<'tcx, Tag>,
+        buf_op: OpTy<'tcx, Tag>,
+    ) -> InterpResult<'tcx, i32> {
+        let this = self.eval_context_mut();
+        this.check_no_isolation("lstat")?;
+        this.stat_or_lstat(false, path_op, buf_op)
+    }
+
+    fn stat_or_lstat(
+        &mut self,
+        follow_symlink: bool,
+        path_op: OpTy<'tcx, Tag>,
+        buf_op: OpTy<'tcx, Tag>,
+    ) -> 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` shim is only available for `macos` targets.")
@@ -322,8 +345,7 @@ fn stat(
 
         let buf = this.deref_operand(buf_op)?;
 
-        // `stat` always follows symlinks. `lstat` is used to get symlink metadata.
-        let metadata = match FileMetadata::new(this, path, true)? {
+        let metadata = match FileMetadata::new(this, path, follow_symlink)? {
             Some(metadata) => metadata,
             None => return Ok(-1),
         };