Skip to content

Commit

Permalink
Haiku: add additional functionality in libbsd.so
Browse files Browse the repository at this point in the history
This includes:
 * sys/event.h: `kevent()`, `kqueue()`, data structure and constants
 * sys/iocomm.h: constants that are also defined for other platforms
 * stdlib.h: `mkstemps()` and `strtonum()`
 * sys/uov.h: `preadv()` and `pwritev()`
 * sys/wait.h: `wait4()`
  • Loading branch information
nielx committed Dec 25, 2024
1 parent 31eee66 commit 00d6fbe
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions src/unix/haiku/bsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ s! {
pub sl_cur: size_t,
}

// sys/event.h
pub struct kevent {
pub ident: crate::uintptr_t,
pub filter: c_short,
pub flags: c_ushort,
pub fflags: c_uint,
pub data: i64,
pub udata: *mut c_void,
pub ext: [u64; 4],
}

// sys/link_elf.h
pub struct dl_phdr_info {
pub dlpi_addr: crate::Elf_Addr,
Expand All @@ -31,6 +42,25 @@ s! {
}
}

// sys/event.h
pub const EVFILT_READ: i16 = -1;
pub const EVFILT_WRITE: i16 = -2;
pub const EVFILT_PROC: i16 = -5;
pub const EV_ADD: u16 = 0x0001;
pub const EV_DELETE: u16 = 0x0002;
pub const EV_ONESHOT: u16 = 0x0010;
pub const EV_CLEAR: u16 = 0x0020;
pub const EV_EOF: u16 = 0x8000;
pub const EV_ERROR: u16 = 0x4000;
pub const NOTE_EXIT: u32 = 0x80000000;

// sys/ioccom.h
pub const IOC_VOID: c_ulong = 0x20000000;
pub const IOC_OUT: c_ulong = 0x40000000;
pub const IOC_IN: c_ulong = 0x80000000;
pub const IOC_INOUT: c_ulong = IOC_IN | IOC_OUT;
pub const IOC_DIRMASK: c_ulong = 0xe0000000;

#[link(name = "bsd")]
extern "C" {
// stdlib.h
Expand All @@ -40,6 +70,13 @@ extern "C" {
pub fn arc4random() -> u32;
pub fn arc4random_uniform(upper_bound: u32) -> u32;
pub fn arc4random_buf(buf: *mut c_void, n: size_t);
pub fn mkstemps(template: *mut c_char, suffixlen: c_int) -> c_int;
pub fn strtonum(
nptr: *const c_char,
minval: c_longlong,
maxval: c_longlong,
errstr: *mut *const c_char,
) -> c_longlong;

// pty.h
pub fn openpty(
Expand Down Expand Up @@ -68,6 +105,17 @@ extern "C" {
pub fn sl_free(sl: *mut StringList, i: c_int);
pub fn sl_find(sl: *mut StringList, n: *mut c_char) -> *mut c_char;

// sys/event.h
pub fn kqueue() -> c_int;
pub fn kevent(
kq: c_int,
changelist: *const kevent,
nchanges: c_int,
eventlist: *mut kevent,
nevents: c_int,
timeout: *const crate::timespec,
) -> c_int;

// sys/link_elf.h
pub fn dl_iterate_phdr(
callback: Option<
Expand All @@ -78,4 +126,26 @@ extern "C" {

// sys/time.h
pub fn lutimes(file: *const c_char, times: *const crate::timeval) -> c_int;

// sys/uov.h
pub fn preadv(
fd: c_int,
iov: *const crate::iovec,
iovcnt: c_int,
offset: crate::off_t,
) -> ssize_t;
pub fn pwritev(
fd: c_int,
iov: *const crate::iovec,
iovcnt: c_int,
offset: crate::off_t,
) -> ssize_t;

// sys/wait.h
pub fn wait4(
pid: crate::pid_t,
status: *mut c_int,
options: c_int,
rusage: *mut crate::rusage,
) -> crate::pid_t;
}

0 comments on commit 00d6fbe

Please sign in to comment.