summaryrefslogtreecommitdiff
path: root/src/backend/libc/shm/syscalls.rs
blob: b0d907ff227ef7aac10c25c491e8a3f97ddc6672 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use crate::ffi::CStr;

use crate::backend::c;
use crate::backend::conv::{c_str, ret, ret_owned_fd};
use crate::fd::OwnedFd;
use crate::fs::Mode;
use crate::io;
use crate::shm::ShmOFlags;

pub(crate) fn shm_open(name: &CStr, oflags: ShmOFlags, mode: Mode) -> io::Result<OwnedFd> {
    // On this platforms, `mode_t` is `u16` and can't be passed directly to a
    // variadic function.
    #[cfg(apple)]
    let mode: c::c_uint = mode.bits().into();

    // Otherwise, cast to `mode_t` as that's what `open` is documented to take.
    #[cfg(not(apple))]
    let mode: c::mode_t = mode.bits() as _;

    unsafe { ret_owned_fd(c::shm_open(c_str(name), bitflags_bits!(oflags), mode)) }
}

pub(crate) fn shm_unlink(name: &CStr) -> io::Result<()> {
    unsafe { ret(c::shm_unlink(c_str(name))) }
}