rustix/fs/
memfd_create.rs

1use crate::fd::OwnedFd;
2use crate::{backend, io, path};
3use backend::fs::types::MemfdFlags;
4
5/// `memfd_create(name, flags)`—Create an anonymous file.
6///
7/// For a higher-level API to this functionality, see the [memfd] crate.
8///
9/// [memfd]: https://crates.io/crates/memfd
10///
11/// # References
12///  - [Linux]
13///  - [glibc]
14///  - [FreeBSD]
15///
16/// [Linux]: https://man7.org/linux/man-pages/man2/memfd_create.2.html
17/// [glibc]: https://sourceware.org/glibc/manual/latest/html_node/Memory_002dmapped-I_002fO.html#index-memfd_005fcreate
18/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?memfd_create
19#[inline]
20pub fn memfd_create<P: path::Arg>(name: P, flags: MemfdFlags) -> io::Result<OwnedFd> {
21    name.into_with_c_str(|name| backend::fs::syscalls::memfd_create(name, flags))
22}