Macro cstr

macro_rules! cstr {
    ($str:literal) => { ... };
}

A macro for CStr literals.

This can make passing string literals to rustix APIs more efficient, since most underlying system calls with string arguments expect NUL-terminated strings, and passing strings to rustix as CStrs means that rustix doesn't need to copy them into a separate buffer to NUL-terminate them.

In Rust ≥ 1.77, users can use C-string literals instead of this macro.

Examples

# #[cfg(feature = "fs")]
# fn main() -> rustix::io::Result<()> {
use rustix::cstr;
use rustix::fs::{statat, AtFlags, CWD};

let metadata = statat(CWD, cstr!("Cargo.toml"), AtFlags::empty())?;
# Ok(())
# }
# #[cfg(not(feature = "fs"))]
# fn main() {}