macro_rules! libc_bitflags {
(
$(#[$outer:meta])*
pub struct $BitFlags:ident: $T:ty {
$(
$(#[$inner:ident $($args:tt)*])*
$Flag:ident $(as $cast:ty)*;
)+
}
) => {
bitflags! {
$(#[$outer])*
pub struct $BitFlags: $T {
$(
$(#[$inner $($args)*])*
const $Flag = libc::$Flag $(as $cast)*;
)+
}
}
};
}
macro_rules! libc_enum {
(@make_enum
{
name: $BitFlags:ident,
attrs: [$($attrs:tt)*],
entries: [$($entries:tt)*],
}
) => {
$($attrs)*
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
enum $BitFlags {
$($entries)*
}
};
(@make_enum
{
pub,
name: $BitFlags:ident,
attrs: [$($attrs:tt)*],
entries: [$($entries:tt)*],
}
) => {
$($attrs)*
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum $BitFlags {
$($entries)*
}
};
(@accumulate_entries
{
name: $BitFlags:ident,
attrs: $attrs:tt,
},
$entries:tt;
) => {
libc_enum! {
@make_enum
{
name: $BitFlags,
attrs: $attrs,
entries: $entries,
}
}
};
(@accumulate_entries
{
pub,
name: $BitFlags:ident,
attrs: $attrs:tt,
},
$entries:tt;
) => {
libc_enum! {
@make_enum
{
pub,
name: $BitFlags,
attrs: $attrs,
entries: $entries,
}
}
};
(@accumulate_entries
$prefix:tt,
[$($entries:tt)*];
#[$attr:meta] $($tail:tt)*
) => {
libc_enum! {
@accumulate_entries
$prefix,
[
$($entries)*
#[$attr]
];
$($tail)*
}
};
(@accumulate_entries
$prefix:tt,
[$($entries:tt)*];
$entry:ident
) => {
libc_enum! {
@accumulate_entries
$prefix,
[
$($entries)*
$entry = libc::$entry,
];
}
};
(@accumulate_entries
$prefix:tt,
[$($entries:tt)*];
$entry:ident, $($tail:tt)*
) => {
libc_enum! {
@accumulate_entries
$prefix,
[
$($entries)*
$entry = libc::$entry,
];
$($tail)*
}
};
(@accumulate_entries
$prefix:tt,
[$($entries:tt)*];
$entry:ident as $ty:ty, $($tail:tt)*
) => {
libc_enum! {
@accumulate_entries
$prefix,
[
$($entries)*
$entry = libc::$entry as $ty,
];
$($tail)*
}
};
(
$(#[$attr:meta])*
enum $BitFlags:ident {
$($vals:tt)*
}
) => {
libc_enum! {
@accumulate_entries
{
name: $BitFlags,
attrs: [$(#[$attr])*],
},
[];
$($vals)*
}
};
(
$(#[$attr:meta])*
pub enum $BitFlags:ident {
$($vals:tt)*
}
) => {
libc_enum! {
@accumulate_entries
{
pub,
name: $BitFlags,
attrs: [$(#[$attr])*],
},
[];
$($vals)*
}
};
}
macro_rules! offset_of {
($ty:ty, $field:ident) => {
&(*(0 as *const $ty)).$field as *const _ as usize
}
}