Skip to content

Commit 31eee66

Browse files
committed
Haiku: move BSD API to a separate file
Haiku implements various parts of the (non-POSIX) BSD API. This moves it to a separate file, for easier future maintenance. No functional change intended; the changes are synchronized with R1Beta5
1 parent 4869273 commit 31eee66

File tree

3 files changed

+109
-69
lines changed

3 files changed

+109
-69
lines changed

src/unix/haiku/bsd.rs

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
use crate::prelude::*;
2+
3+
// This file contains the BSD APIs available in Haiku. It corresponds to the
4+
// header files in `headers/compatibility/bsd`.
5+
//
6+
// Note that Haiku's BSD compatibility is a combination of system APIs and
7+
// utility libraries. There should only be system APIs in `libc`. When you are
8+
// trying to determine whether something should be included in this file, the
9+
// best indicator is whether it also exists in the BSD-specific definitions in
10+
// this libc crate.
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/link_elf.h
26+
pub struct dl_phdr_info {
27+
pub dlpi_addr: crate::Elf_Addr,
28+
pub dlpi_name: *const c_char,
29+
pub dlpi_phdr: *const crate::Elf_Phdr,
30+
pub dlpi_phnum: crate::Elf_Half,
31+
}
32+
}
33+
34+
#[link(name = "bsd")]
35+
extern "C" {
36+
// stdlib.h
37+
pub fn daemon(nochdir: c_int, noclose: c_int) -> c_int;
38+
pub fn getprogname() -> *const c_char;
39+
pub fn setprogname(progname: *const c_char);
40+
pub fn arc4random() -> u32;
41+
pub fn arc4random_uniform(upper_bound: u32) -> u32;
42+
pub fn arc4random_buf(buf: *mut c_void, n: size_t);
43+
44+
// pty.h
45+
pub fn openpty(
46+
amaster: *mut c_int,
47+
aslave: *mut c_int,
48+
name: *mut c_char,
49+
termp: *mut crate::termios,
50+
winp: *mut crate::winsize,
51+
) -> c_int;
52+
pub fn login_tty(_fd: c_int) -> c_int;
53+
pub fn forkpty(
54+
amaster: *mut c_int,
55+
name: *mut c_char,
56+
termp: *mut crate::termios,
57+
winp: *mut crate::winsize,
58+
) -> crate::pid_t;
59+
60+
// string.h
61+
pub fn strsep(string: *mut *mut c_char, delimiters: *const c_char) -> *mut c_char;
62+
pub fn explicit_bzero(buf: *mut c_void, len: size_t);
63+
64+
// stringlist.h (utility library)
65+
// Note: this is kept because it was previously introduced
66+
pub fn sl_init() -> *mut StringList;
67+
pub fn sl_add(sl: *mut StringList, n: *mut c_char) -> c_int;
68+
pub fn sl_free(sl: *mut StringList, i: c_int);
69+
pub fn sl_find(sl: *mut StringList, n: *mut c_char) -> *mut c_char;
70+
71+
// sys/link_elf.h
72+
pub fn dl_iterate_phdr(
73+
callback: Option<
74+
unsafe extern "C" fn(info: *mut dl_phdr_info, size: usize, data: *mut c_void) -> c_int,
75+
>,
76+
data: *mut c_void,
77+
) -> c_int;
78+
79+
// sys/time.h
80+
pub fn lutimes(file: *const c_char, times: *const crate::timeval) -> c_int;
81+
}

src/unix/haiku/mod.rs

+27-56
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
use crate::prelude::*;
22

3+
// This module contains bindings to the native Haiku API. The Haiku API
4+
// originates from BeOS, and it was the original way to perform low level
5+
// system and IO operations. The POSIX API was in that era was like a
6+
// compatibility layer. In current Haiku development, both the POSIX API and
7+
// the Haiku API are considered to be co-equal status. However, they are not
8+
// integrated like they are on other UNIX platforms, which means that for many
9+
// low level concepts there are two versions, like processes (POSIX) and
10+
// teams (Haiku), or pthreads and native threads.
11+
//
12+
// Both the POSIX API and the Haiku API live in libroot.so, the library that is
13+
// linked to any binary by default. Additionally, Haiku supports several
14+
// non-POSIX APIs from BSD and GNU, which live in libbsd.so and libgnu.so. These
15+
// modules are also supported.
16+
//
17+
// The module is comprised of the following files:
18+
// - `mod.rs` (this file) implements the C11 and POSIX API found in
19+
// `headers/posix`
20+
// - `b32.rs`, `b64.rs` and `x86_64.rs` contain platform-specific definitions
21+
// of the C11 and POSIX APIs
22+
// - `native.rs` defines the native Haiku API that is implemented in
23+
// `libroot.so` and that are found in `headers/os`.
24+
// - `bsd.rs` defines the BSD customizations available on Haiku found in
25+
// `headers/compatibility/bsd`
26+
327
pub type rlim_t = crate::uintptr_t;
428
pub type sa_family_t = u8;
529
pub type pthread_key_t = c_int;
@@ -56,8 +80,6 @@ pub type ACTION = c_int;
5680
pub type posix_spawnattr_t = *mut c_void;
5781
pub type posix_spawn_file_actions_t = *mut c_void;
5882

59-
pub type StringList = _stringlist;
60-
6183
#[cfg_attr(feature = "extra_traits", derive(Debug))]
6284
pub enum timezone {}
6385
impl Copy for timezone {}
@@ -440,19 +462,6 @@ s! {
440462
pub flag: *mut c_int,
441463
pub val: c_int,
442464
}
443-
444-
pub struct _stringlist {
445-
pub sl_str: *mut *mut c_char,
446-
pub sl_max: size_t,
447-
pub sl_cur: size_t,
448-
}
449-
450-
pub struct dl_phdr_info {
451-
pub dlpi_addr: crate::Elf_Addr,
452-
pub dlpi_name: *const c_char,
453-
pub dlpi_phdr: *const crate::Elf_Phdr,
454-
pub dlpi_phnum: crate::Elf_Half,
455-
}
456465
}
457466

458467
s_no_extra_traits! {
@@ -1829,7 +1838,6 @@ extern "C" {
18291838
addr: *mut crate::sockaddr,
18301839
addrlen: *mut crate::socklen_t,
18311840
) -> ssize_t;
1832-
pub fn mkstemps(template: *mut c_char, suffixlen: c_int) -> c_int;
18331841
pub fn nl_langinfo(item: crate::nl_item) -> *mut c_char;
18341842

18351843
pub fn bind(
@@ -2086,46 +2094,6 @@ extern "C" {
20862094
pub fn getentropy(buf: *mut c_void, buflen: size_t) -> c_int;
20872095
}
20882096

2089-
#[link(name = "bsd")]
2090-
extern "C" {
2091-
pub fn lutimes(file: *const c_char, times: *const crate::timeval) -> c_int;
2092-
pub fn daemon(nochdir: c_int, noclose: c_int) -> c_int;
2093-
pub fn forkpty(
2094-
amaster: *mut c_int,
2095-
name: *mut c_char,
2096-
termp: *mut termios,
2097-
winp: *mut crate::winsize,
2098-
) -> crate::pid_t;
2099-
pub fn openpty(
2100-
amaster: *mut c_int,
2101-
aslave: *mut c_int,
2102-
name: *mut c_char,
2103-
termp: *mut termios,
2104-
winp: *mut crate::winsize,
2105-
) -> c_int;
2106-
pub fn strsep(string: *mut *mut c_char, delimiters: *const c_char) -> *mut c_char;
2107-
pub fn explicit_bzero(buf: *mut c_void, len: size_t);
2108-
pub fn login_tty(_fd: c_int) -> c_int;
2109-
2110-
pub fn sl_init() -> *mut StringList;
2111-
pub fn sl_add(sl: *mut StringList, n: *mut c_char) -> c_int;
2112-
pub fn sl_free(sl: *mut StringList, i: c_int);
2113-
pub fn sl_find(sl: *mut StringList, n: *mut c_char) -> *mut c_char;
2114-
2115-
pub fn getprogname() -> *const c_char;
2116-
pub fn setprogname(progname: *const c_char);
2117-
pub fn dl_iterate_phdr(
2118-
callback: Option<
2119-
unsafe extern "C" fn(info: *mut dl_phdr_info, size: usize, data: *mut c_void) -> c_int,
2120-
>,
2121-
data: *mut c_void,
2122-
) -> c_int;
2123-
2124-
pub fn arc4random() -> u32;
2125-
pub fn arc4random_uniform(upper_bound: u32) -> u32;
2126-
pub fn arc4random_buf(buf: *mut c_void, n: size_t);
2127-
}
2128-
21292097
#[link(name = "gnu")]
21302098
extern "C" {
21312099
pub fn memmem(
@@ -2169,5 +2137,8 @@ cfg_if! {
21692137
}
21702138
}
21712139

2140+
mod bsd;
2141+
pub use self::bsd::*;
2142+
21722143
mod native;
21732144
pub use self::native::*;

src/unix/haiku/native.rs

+1-13
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
11
use crate::off_t;
22
use crate::prelude::*;
33

4-
// This module contains bindings to the native Haiku API. The Haiku API
5-
// originates from BeOS, and it was the original way to perform low level
6-
// system and IO operations. The POSIX API was in that era was like a
7-
// compatibility layer. In current Haiku development, both the POSIX API and
8-
// the Haiku API are considered to be co-equal status. However, they are not
9-
// integrated like they are on other UNIX platforms, which means that for many
10-
// low level concepts there are two versions, like processes (POSIX) and
11-
// teams (Haiku), or pthreads and native threads.
12-
//
13-
// Both the POSIX API and the Haiku API live in libroot.so, the library that is
14-
// linked to any binary by default.
15-
//
16-
// This file follows the Haiku API for Haiku R1 beta 2. It is organized by the
4+
// This file follows the Haiku API for Haiku R1 beta 5. It is organized by the
175
// C/C++ header files in which the concepts can be found, while adhering to the
186
// style guide for this crate.
197

0 commit comments

Comments
 (0)