From 00d6fbef8a79ae658d19c147805333835e724c17 Mon Sep 17 00:00:00 2001 From: Niels Sascha Reedijk Date: Wed, 25 Dec 2024 16:54:36 +0000 Subject: [PATCH] Haiku: add additional functionality in libbsd.so 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()` --- src/unix/haiku/bsd.rs | 70 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/src/unix/haiku/bsd.rs b/src/unix/haiku/bsd.rs index 32a0837f6c14..aebb01f1a200 100644 --- a/src/unix/haiku/bsd.rs +++ b/src/unix/haiku/bsd.rs @@ -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, @@ -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 @@ -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( @@ -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< @@ -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; }