MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / open

Function open

src/backend/libc/fs/syscalls.rs:146–177  ·  view source on GitHub ↗
(path: &CStr, oflags: OFlags, mode: Mode)

Source from the content-addressed store, hash-verified

144}
145
146pub(crate) fn open(path: &CStr, oflags: OFlags, mode: Mode) -> io::Result<OwnedFd> {
147 // Work around <https://sourceware.org/bugzilla/show_bug.cgi?id=17523>.
148 // glibc versions before 2.25 don't handle `O_TMPFILE` correctly.
149 #[cfg(all(
150 unix,
151 target_env = "gnu",
152 not(target_os = "hurd"),
153 not(target_os = "freebsd")
154 ))]
155 if oflags.contains(OFlags::TMPFILE) && crate::backend::if_glibc_is_less_than_2_25() {
156 return open_via_syscall(path, oflags, mode);
157 }
158
159 // On these platforms, `mode_t` is `u16` and can't be passed directly to a
160 // variadic function.
161 #[cfg(any(
162 apple,
163 freebsdlike,
164 all(target_os = "android", target_pointer_width = "32")
165 ))]
166 let mode: c::c_uint = mode.bits().into();
167
168 // Otherwise, cast to `mode_t` as that's what `open` is documented to take.
169 #[cfg(not(any(
170 apple,
171 freebsdlike,
172 all(target_os = "android", target_pointer_width = "32")
173 )))]
174 let mode: c::mode_t = mode.bits() as _;
175
176 unsafe { ret_owned_fd(c::open(c_str(path), bitflags_bits!(oflags), mode)) }
177}
178
179/// Use a direct syscall (via libc) for `openat`.
180///

Callers 1

open_via_syscallFunction · 0.70

Calls 5

open_via_syscallFunction · 0.85
c_strFunction · 0.85
containsMethod · 0.80
ret_owned_fdFunction · 0.50

Tested by

no test coverage detected