Macro nix::macros::libc_bitflags

source ·
macro_rules! libc_bitflags {
    (
        $(#[$outer:meta])*
        pub struct $BitFlags:ident: $T:ty {
            $(
                $(#[$inner:ident $($args:tt)*])*
                $Flag:ident $(as $cast:ty)*;
            )+
        }
    ) => { ... };
}
Expand description

The libc_bitflags! macro helps with a common use case of defining a public bitflags type with values from the libc crate. It is used the same way as the bitflags! macro, except that only the name of the flag value has to be given.

The libc crate must be in scope with the name libc.

Example

libc_bitflags!{
    pub struct ProtFlags: libc::c_int {
        PROT_NONE;
        PROT_READ;
        /// PROT_WRITE enables write protect
        PROT_WRITE;
        PROT_EXEC;
        #[cfg(linux_android)]
        PROT_GROWSDOWN;
        #[cfg(linux_android)]
        PROT_GROWSUP;
    }
}

Example with casting, due to a mistake in libc. In this example, the various flags have different types, so we cast the broken ones to the right type.

libc_bitflags!{
    pub struct SaFlags: libc::c_ulong {
        SA_NOCLDSTOP as libc::c_ulong;
        SA_NOCLDWAIT;
        SA_NODEFER as libc::c_ulong;
        SA_ONSTACK;
        SA_RESETHAND as libc::c_ulong;
        SA_RESTART as libc::c_ulong;
        SA_SIGINFO;
    }
}