Skip to content

Commit

Permalink
Provide the EV_SET macro and nevents_type
Browse files Browse the repository at this point in the history
both to make working with kevent easier across BSD variants
  • Loading branch information
vojtechkral committed Oct 5, 2017
1 parent e4f8ab8 commit 5daaeb3
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
3 changes: 3 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,9 @@ fn main() {
// sighandler_t is crazy across platforms
"sighandler_t" => true,

// A helper type for kqueue platforms, not actually defined on the system
"nevents_type" => true,

_ => false
}
});
Expand Down
16 changes: 16 additions & 0 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub type nl_item = ::c_int;
pub type id_t = ::c_uint;
pub type sem_t = ::c_int;
pub type idtype_t = ::c_uint;
pub type nevents_type = ::c_int;

pub enum timezone {}

Expand Down Expand Up @@ -413,6 +414,21 @@ s! {
}
}

#[macro_export]
macro_rules! EV_SET {
($ident:expr, $filter:expr, $flags:expr, $fflags:expr,
$data:expr, $udata:expr) => {
kevent {
ident: $ident as ::libc::uintptr_t,
filter: $filter as ::libc::int16_t,
flags: $flags as ::libc::uint16_t,
fflags: $fflags as ::libc::uint32_t,
data: $data as ::libc::intptr_t,
udata: $udata as *mut ::libc::c_void,
}
}
}

pub const _UTX_USERSIZE: usize = 256;
pub const _UTX_LINESIZE: usize = 32;
pub const _UTX_IDSIZE: usize = 4;
Expand Down
16 changes: 16 additions & 0 deletions src/unix/bsd/freebsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub type tcflag_t = ::c_uint;
pub type speed_t = ::c_uint;
pub type nl_item = ::c_int;
pub type id_t = i64;
pub type nevents_type = ::c_int;

pub enum timezone {}

Expand Down Expand Up @@ -161,6 +162,21 @@ s! {
}
}

#[macro_export]
macro_rules! EV_SET {
($ident:expr, $filter:expr, $flags:expr, $fflags:expr,
$data:expr, $udata:expr) => {
kevent {
ident: $ident as ::libc::uintptr_t,
filter: $filter as ::libc::c_short,
flags: $flags as ::libc::c_ushort,
fflags: $fflags as ::libc::c_uint,
data: $data as ::libc::intptr_t,
udata: $udata as *mut ::libc::c_void,
}
}
}

pub const AIO_LISTIO_MAX: ::c_int = 16;
pub const AIO_CANCELED: ::c_int = 1;
pub const AIO_NOTCANCELED: ::c_int = 2;
Expand Down
16 changes: 16 additions & 0 deletions src/unix/bsd/netbsdlike/netbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub type blksize_t = ::int32_t;
pub type fsblkcnt_t = ::uint64_t;
pub type fsfilcnt_t = ::uint64_t;
pub type idtype_t = ::c_int;
pub type nevents_type = ::size_t;

s! {
pub struct aiocb {
Expand Down Expand Up @@ -283,6 +284,21 @@ s! {
}
}

#[macro_export]
macro_rules! EV_SET {
($ident:expr, $filter:expr, $flags:expr, $fflags:expr,
$data:expr, $udata:expr) => {
kevent {
ident: $ident as ::libc::uintptr_t,
filter: $filter as ::libc::uint32_t,
flags: $flags as ::libc::uint32_t,
fflags: $fflags as ::libc::uint32_t,
data: $data as ::libc::int64_t,
udata: $udata as ::libc::intptr_t,
}
}
}

pub const AT_FDCWD: ::c_int = -100;
pub const AT_EACCESS: ::c_int = 0x100;
pub const AT_SYMLINK_NOFOLLOW: ::c_int = 0x200;
Expand Down
16 changes: 16 additions & 0 deletions src/unix/bsd/netbsdlike/openbsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub type pthread_cond_t = *mut ::c_void;
pub type pthread_condattr_t = *mut ::c_void;
pub type pthread_rwlock_t = *mut ::c_void;
pub type pthread_rwlockattr_t = *mut ::c_void;
pub type nevents_type = ::c_int;

s! {
pub struct dirent {
Expand Down Expand Up @@ -178,6 +179,21 @@ s! {
}
}

#[macro_export]
macro_rules! EV_SET {
($ident:expr, $filter:expr, $flags:expr, $fflags:expr,
$data:expr, $udata:expr) => {
kevent {
ident: $ident as ::libc::uintptr_t,
filter: $filter as ::libc::c_short,
flags: $flags as ::libc::c_ushort,
fflags: $fflags as ::libc::c_uint,
data: $data as ::libc::int64_t,
udata: $udata as *mut ::libc::c_void,
}
}
}

pub const UT_NAMESIZE: usize = 32;
pub const UT_LINESIZE: usize = 8;
pub const UT_HOSTSIZE: usize = 256;
Expand Down

0 comments on commit 5daaeb3

Please sign in to comment.