]> git.lizzy.rs Git - rust.git/commitdiff
fs shim: check that mode is default
authorRalf Jung <post@ralfj.de>
Tue, 5 May 2020 14:49:01 +0000 (16:49 +0200)
committerRalf Jung <post@ralfj.de>
Tue, 5 May 2020 14:49:01 +0000 (16:49 +0200)
src/shims/fs.rs

index 58abf748dd5a86179edd5615abde96ef0f630657..0de0b33fb2e29accda6c87c0b7db25524695a82b 100644 (file)
@@ -246,18 +246,13 @@ fn open(
 
         let flag = this.read_scalar(flag_op)?.to_i32()?;
 
-        // Check mode (size depends on platform).
-        // FIXME: should we do something with the mode?
-        match this.tcx.sess.target.target.target_os.as_str() {
-            "macos" => {
-                // FIXME: I think `mode` should be `u16` on macOS, but see
-                // <https://github.com/rust-lang/rust/issues/71915>.
-                // For now, just don't check on macos.
-            }
-            _ => {
-                this.read_scalar(mode_op)?.to_u32()?;
-            }
-        };
+        // Get the mode.  On macOS, the argument type `mode_t` is actually `u16`, but
+        // C integer promotion rules mean that on the ABI level, it gets passed as `u32`
+        // (see https://github.com/rust-lang/rust/issues/71915).
+        let mode = this.read_scalar(mode_op)?.to_u32()?;
+        if mode != 0o666 {
+            throw_unsup_format!("non-default mode 0o{:o} is not supported", mode);
+        }
 
         let mut options = OpenOptions::new();