Skip to content

Commit

Permalink
Provide kevent::new(), an EV_SET analogue, 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 1, 2017
1 parent e4f8ab8 commit f7c3e97
Show file tree
Hide file tree
Showing 5 changed files with 82 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 BSD platform, not actually defined on the system
"nevents_type" => true,

_ => false
}
});
Expand Down
19 changes: 19 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,24 @@ s! {
}
}

impl kevent {
/// Constructs a `kevent` structure. This is an analogue
/// of the libc `EV_SET` macro and has the same signature
/// across BSD variants.
pub fn new(ident: usize, filter: i16, flags: u16,
fflags: u32, data: isize, udata: usize) -> kevent {
// The types of the various filter & flags args are the same
// as the appropriate integer constants so as to make the usage easier
kevent {
ident: ident,
filter: filter,
flags: flags,
fflags: fflags,
data: data,
udata: udata as *mut ::c_void,
}
}
}
pub const _UTX_USERSIZE: usize = 256;
pub const _UTX_LINESIZE: usize = 32;
pub const _UTX_IDSIZE: usize = 4;
Expand Down
20 changes: 20 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,25 @@ s! {
}
}

impl kevent {
/// Constructs a `kevent` structure. This is an analogue
/// of the libc `EV_SET` macro and has the same signature
/// across BSD variants.
pub fn new(ident: usize, filter: i16, flags: u16,
fflags: u32, data: isize, udata: usize) -> kevent {
// The types of the various filter & flags args are the same
// as the appropriate integer constants so as to make the usage easier
kevent {
ident: ident,
filter: filter as ::c_short,
flags: flags as ::c_ushort,
fflags: fflags as ::c_uint,
data: data,
udata: udata as *mut ::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
20 changes: 20 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,25 @@ s! {
}
}

impl kevent {
/// Constructs a `kevent` structure. This is an analogue
/// of the libc `EV_SET` macro and has the same signature
/// across BSD variants.
pub fn new(ident: usize, filter: i16, flags: u16,
fflags: u32, data: isize, udata: usize) -> kevent {
// The types of the various filter & flags args are the same
// as the appropriate integer constants so as to make the usage easier
kevent {
ident: ident,
filter: filter as ::uint32_t,
flags: flags as ::uint32_t,
fflags: fflags,
data: data as ::int64_t,
udata: udata as ::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
20 changes: 20 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,25 @@ s! {
}
}

impl kevent {
/// Constructs a `kevent` structure. This is an analogue
/// of the libc `EV_SET` macro and has the same signature
/// across BSD variants.
pub fn new(ident: usize, filter: i16, flags: u16,
fflags: u32, data: isize, udata: usize) -> kevent {
// The types of the various filter & flags args are the same
// as the appropriate integer constants so as to make the usage easier
kevent {
ident: ident,
filter: filter as ::c_short,
flags: flags as ::c_ushort,
fflags: fflags as ::c_uint,
data: data as ::int64_t,
udata: udata as *mut ::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 f7c3e97

Please sign in to comment.