| 1 |
//! This file contains the BSD APIs available in Haiku. It corresponds to the |
| 2 |
//! header files in `headers/compatibility/bsd`. |
| 3 |
//! |
| 4 |
//! Note that Haiku's BSD compatibility is a combination of system APIs and |
| 5 |
//! utility libraries. There should only be system APIs in `libc`. When you are |
| 6 |
//! trying to determine whether something should be included in this file, the |
| 7 |
//! best indicator is whether it also exists in the BSD-specific definitions in |
| 8 |
//! this libc crate. |
| 9 |
|
| 10 |
use crate::prelude::*; |
| 11 |
|
| 12 |
// stringlist.h (utility library) |
| 13 |
// Note: this is kept because it was previously introduced |
| 14 |
pub type StringList = _stringlist; |
| 15 |
|
| 16 |
s! { |
| 17 |
// stringlist.h (utility library) |
| 18 |
// Note: this is kept because it was previously introduced |
| 19 |
pub struct _stringlist { |
| 20 |
pub sl_str: *mut *mut c_char, |
| 21 |
pub sl_max: size_t, |
| 22 |
pub sl_cur: size_t, |
| 23 |
} |
| 24 |
|
| 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 |
|
| 36 |
// sys/link_elf.h |
| 37 |
pub struct dl_phdr_info { |
| 38 |
pub dlpi_addr: crate::Elf_Addr, |
| 39 |
pub dlpi_name: *const c_char, |
| 40 |
pub dlpi_phdr: *const crate::Elf_Phdr, |
| 41 |
pub dlpi_phnum: crate::Elf_Half, |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 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 |
|
| 64 |
#[link(name = "bsd")] |
| 65 |
extern "C" { |
| 66 |
// stdlib.h |
| 67 |
pub fn daemon(nochdir: c_int, noclose: c_int) -> c_int; |
| 68 |
pub fn getprogname() -> *const c_char; |
| 69 |
pub fn setprogname(progname: *const c_char); |
| 70 |
pub fn arc4random() -> u32; |
| 71 |
pub fn arc4random_uniform(upper_bound: u32) -> u32; |
| 72 |
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; |
| 80 |
|
| 81 |
// pty.h |
| 82 |
pub fn openpty( |
| 83 |
amaster: *mut c_int, |
| 84 |
aslave: *mut c_int, |
| 85 |
name: *mut c_char, |
| 86 |
termp: *mut crate::termios, |
| 87 |
winp: *mut crate::winsize, |
| 88 |
) -> c_int; |
| 89 |
pub fn login_tty(_fd: c_int) -> c_int; |
| 90 |
pub fn forkpty( |
| 91 |
amaster: *mut c_int, |
| 92 |
name: *mut c_char, |
| 93 |
termp: *mut crate::termios, |
| 94 |
winp: *mut crate::winsize, |
| 95 |
) -> crate::pid_t; |
| 96 |
|
| 97 |
// string.h |
| 98 |
pub fn strsep(string: *mut *mut c_char, delimiters: *const c_char) -> *mut c_char; |
| 99 |
pub fn explicit_bzero(buf: *mut c_void, len: size_t); |
| 100 |
|
| 101 |
// stringlist.h (utility library) |
| 102 |
// Note: this is kept because it was previously introduced |
| 103 |
pub fn sl_init() -> *mut StringList; |
| 104 |
pub fn sl_add(sl: *mut StringList, n: *mut c_char) -> c_int; |
| 105 |
pub fn sl_free(sl: *mut StringList, i: c_int); |
| 106 |
pub fn sl_find(sl: *mut StringList, n: *mut c_char) -> *mut c_char; |
| 107 |
|
| 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 |
|
| 119 |
// sys/link_elf.h |
| 120 |
pub fn dl_iterate_phdr( |
| 121 |
callback: Option< |
| 122 |
unsafe extern "C" fn(info: *mut dl_phdr_info, size: usize, data: *mut c_void) -> c_int, |
| 123 |
>, |
| 124 |
data: *mut c_void, |
| 125 |
) -> c_int; |
| 126 |
|
| 127 |
// sys/time.h |
| 128 |
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; |
| 151 |
} |