Debian Codegraph @

debian/rust-vendor/rustix/src/backend/libc/shm/syscalls.rs

raw
1 use crate::ffi::CStr;
2
3 use crate::backend::c;
4 use crate::backend::conv::{c_str, ret, ret_owned_fd};
5 use crate::fd::OwnedFd;
6 use crate::fs::Mode;
7 use crate::{io, shm};
8
9 pub(crate) fn shm_open(name: &CStr, oflags: shm::OFlags, mode: Mode) -> io::Result<OwnedFd> {
10 // On this platforms, `mode_t` is `u16` and can't be passed directly to a
11 // variadic function.
12 #[cfg(apple)]
13 let mode: c::c_uint = mode.bits().into();
14
15 // Otherwise, cast to `mode_t` as that's what `open` is documented to take.
16 #[cfg(not(apple))]
17 let mode: c::mode_t = mode.bits() as _;
18
19 unsafe { ret_owned_fd(c::shm_open(c_str(name), bitflags_bits!(oflags), mode)) }
20 }
21
22 pub(crate) fn shm_unlink(name: &CStr) -> io::Result<()> {
23 unsafe { ret(c::shm_unlink(c_str(name))) }
24 }