Skip to content

Commit b86620a

Browse files
authored
Rollup merge of #71921 - RalfJung:open-mode, r=hanna-kruppe
explain the types used in the open64 call Fixes #71915, where I learned about this quirk. I don't actually know what I am talking about here. ;)
2 parents f29a923 + fbf791b commit b86620a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/libstd/sys/unix/fs.rs

+4
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,10 @@ impl File {
703703
| opts.get_access_mode()?
704704
| opts.get_creation_mode()?
705705
| (opts.custom_flags as c_int & !libc::O_ACCMODE);
706+
// The third argument of `open64` is documented to have type `mode_t`. On
707+
// some platforms (like macOS, where `open64` is actually `open`), `mode_t` is `u16`.
708+
// However, since this is a variadic function, C integer promotion rules mean that on
709+
// the ABI level, this still gets passed as `c_int` (aka `u32` on Unix platforms).
706710
let fd = cvt_r(|| unsafe { open64(path.as_ptr(), flags, opts.mode as c_int) })?;
707711
let fd = FileDesc::new(fd);
708712

0 commit comments

Comments
 (0)