c-scape 0.22.3

A libc bottom-half implementation in Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use crate::convert_res;
use core::ffi::CStr;
use libc::{c_char, c_int, c_uint};
use rustix::fd::IntoRawFd;
use rustix::fs::MemfdFlags;

#[no_mangle]
unsafe extern "C" fn memfd_create(name: *const c_char, flags: c_uint) -> c_int {
    libc!(libc::memfd_create(name, flags));

    let name = CStr::from_ptr(name);
    let flags = MemfdFlags::from_bits_retain(flags);
    match convert_res(rustix::fs::memfd_create(name, flags)) {
        Some(fd) => fd.into_raw_fd(),
        None => -1,
    }
}