Skip to content

Commit 00d6fbe

Browse files
committed
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()`
1 parent 31eee66 commit 00d6fbe

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

src/unix/haiku/bsd.rs

+70
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ s! {
2222
pub sl_cur: size_t,
2323
}
2424

25+
// sys/event.h
26+
pub struct kevent {
27+
pub ident: crate::uintptr_t,
28+
pub filter: c_short,
29+
pub flags: c_ushort,
30+
pub fflags: c_uint,
31+
pub data: i64,
32+
pub udata: *mut c_void,
33+
pub ext: [u64; 4],
34+
}
35+
2536
// sys/link_elf.h
2637
pub struct dl_phdr_info {
2738
pub dlpi_addr: crate::Elf_Addr,
@@ -31,6 +42,25 @@ s! {
3142
}
3243
}
3344

45+
// sys/event.h
46+
pub const EVFILT_READ: i16 = -1;
47+
pub const EVFILT_WRITE: i16 = -2;
48+
pub const EVFILT_PROC: i16 = -5;
49+
pub const EV_ADD: u16 = 0x0001;
50+
pub const EV_DELETE: u16 = 0x0002;
51+
pub const EV_ONESHOT: u16 = 0x0010;
52+
pub const EV_CLEAR: u16 = 0x0020;
53+
pub const EV_EOF: u16 = 0x8000;
54+
pub const EV_ERROR: u16 = 0x4000;
55+
pub const NOTE_EXIT: u32 = 0x80000000;
56+
57+
// sys/ioccom.h
58+
pub const IOC_VOID: c_ulong = 0x20000000;
59+
pub const IOC_OUT: c_ulong = 0x40000000;
60+
pub const IOC_IN: c_ulong = 0x80000000;
61+
pub const IOC_INOUT: c_ulong = IOC_IN | IOC_OUT;
62+
pub const IOC_DIRMASK: c_ulong = 0xe0000000;
63+
3464
#[link(name = "bsd")]
3565
extern "C" {
3666
// stdlib.h
@@ -40,6 +70,13 @@ extern "C" {
4070
pub fn arc4random() -> u32;
4171
pub fn arc4random_uniform(upper_bound: u32) -> u32;
4272
pub fn arc4random_buf(buf: *mut c_void, n: size_t);
73+
pub fn mkstemps(template: *mut c_char, suffixlen: c_int) -> c_int;
74+
pub fn strtonum(
75+
nptr: *const c_char,
76+
minval: c_longlong,
77+
maxval: c_longlong,
78+
errstr: *mut *const c_char,
79+
) -> c_longlong;
4380

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

108+
// sys/event.h
109+
pub fn kqueue() -> c_int;
110+
pub fn kevent(
111+
kq: c_int,
112+
changelist: *const kevent,
113+
nchanges: c_int,
114+
eventlist: *mut kevent,
115+
nevents: c_int,
116+
timeout: *const crate::timespec,
117+
) -> c_int;
118+
71119
// sys/link_elf.h
72120
pub fn dl_iterate_phdr(
73121
callback: Option<
@@ -78,4 +126,26 @@ extern "C" {
78126

79127
// sys/time.h
80128
pub fn lutimes(file: *const c_char, times: *const crate::timeval) -> c_int;
129+
130+
// sys/uov.h
131+
pub fn preadv(
132+
fd: c_int,
133+
iov: *const crate::iovec,
134+
iovcnt: c_int,
135+
offset: crate::off_t,
136+
) -> ssize_t;
137+
pub fn pwritev(
138+
fd: c_int,
139+
iov: *const crate::iovec,
140+
iovcnt: c_int,
141+
offset: crate::off_t,
142+
) -> ssize_t;
143+
144+
// sys/wait.h
145+
pub fn wait4(
146+
pid: crate::pid_t,
147+
status: *mut c_int,
148+
options: c_int,
149+
rusage: *mut crate::rusage,
150+
) -> crate::pid_t;
81151
}

0 commit comments

Comments
 (0)