Skip to content

Commit ae3414c

Browse files
committed
Auto merge of #2769 - jessicah:haiku, r=Amanieu
haiku: improve platform compatibility * Also moves a number functions out of the `libbsd` module, as these are actually in `libroot`, so don't require linking against `libbsd`. * `dl_iterate_phdr` is not implemented. * `B_FILE_NOT_FOUND` has been deprecated, and removed from the public headers
2 parents 3b5fcd6 + a7cba7c commit ae3414c

File tree

3 files changed

+232
-57
lines changed

3 files changed

+232
-57
lines changed

libc-test/build.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3685,6 +3685,7 @@ fn test_haiku(target: &str) {
36853685
cfg.flag("-Wno-deprecated-declarations");
36863686
cfg.define("__USE_GNU", Some("1"));
36873687
cfg.define("_GNU_SOURCE", None);
3688+
cfg.language(ctest::Lang::CXX);
36883689

36893690
// POSIX API
36903691
headers! { cfg:
@@ -3728,7 +3729,6 @@ fn test_haiku(target: &str) {
37283729
"net/if_types.h",
37293730
"net/route.h",
37303731
"netdb.h",
3731-
"netinet/icmp6.h",
37323732
"netinet/in.h",
37333733
"netinet/ip.h",
37343734
"netinet/ip6.h",
@@ -3886,6 +3886,9 @@ fn test_haiku(target: &str) {
38863886

38873887
"get_cpuid" => true,
38883888

3889+
// uses varargs parameter
3890+
"ioctl" => true,
3891+
38893892
_ => false,
38903893
}
38913894
});
@@ -3960,6 +3963,9 @@ fn test_haiku(target: &str) {
39603963
| "object_wait_info" | "image_info" | "attr_info" | "index_info" | "fs_info"
39613964
| "FILE" | "DIR" | "Dl_info" => ty.to_string(),
39623965

3966+
// enums don't need a prefix
3967+
"directory_which" | "path_base_directory" => ty.to_string(),
3968+
39633969
// is actually a union
39643970
"sigval" => format!("union sigval"),
39653971
t if is_union => format!("union {}", t),

src/unix/haiku/mod.rs

Lines changed: 192 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ pub type fsfilcnt_t = i64;
2828
pub type pthread_attr_t = *mut ::c_void;
2929
pub type nl_item = ::c_int;
3030
pub type id_t = i32;
31-
pub type idtype_t = ::c_uint;
31+
pub type idtype_t = ::c_int;
3232
pub type fd_mask = u32;
33+
pub type regoff_t = ::c_int;
34+
pub type key_t = i32;
35+
pub type msgqnum_t = u32;
36+
pub type msglen_t = u32;
3337

3438
pub type Elf32_Addr = u32;
3539
pub type Elf32_Half = u16;
@@ -45,6 +49,9 @@ pub type Elf64_Sxword = i64;
4549
pub type Elf64_Word = u32;
4650
pub type Elf64_Xword = u64;
4751

52+
pub type ENTRY = entry;
53+
pub type ACTION = ::c_int;
54+
4855
#[cfg_attr(feature = "extra_traits", derive(Debug))]
4956
pub enum timezone {}
5057
impl ::Copy for timezone {}
@@ -362,17 +369,6 @@ s! {
362369
pub sdl_data: [u8; 46],
363370
}
364371

365-
pub struct dl_phdr_info {
366-
pub dlpi_addr: Elf_Addr,
367-
pub dlpi_name: *const ::c_char,
368-
pub dlpi_phdr: *const Elf_Phdr,
369-
pub dlpi_phnum: Elf_Half,
370-
pub dlpi_adds: ::c_ulonglong,
371-
pub dlpi_subs: ::c_ulonglong,
372-
pub dlpi_tls_modid: usize,
373-
pub dlpi_tls_data: *mut ::c_void,
374-
}
375-
376372
pub struct spwd {
377373
pub sp_namp: *mut ::c_char,
378374
pub sp_pwdp: *mut ::c_char,
@@ -384,6 +380,53 @@ s! {
384380
pub sp_expire: ::c_int,
385381
pub sp_flag: ::c_int,
386382
}
383+
384+
pub struct regex_t {
385+
__buffer: *mut ::c_void,
386+
__allocated: ::size_t,
387+
__used: ::size_t,
388+
__syntax: ::c_ulong,
389+
__fastmap: *mut ::c_char,
390+
__translate: *mut ::c_char,
391+
__re_nsub: ::size_t,
392+
__bitfield: u8,
393+
}
394+
395+
pub struct regmatch_t {
396+
pub rm_so: regoff_t,
397+
pub rm_eo: regoff_t,
398+
}
399+
400+
pub struct msqid_ds {
401+
pub msg_perm: ::ipc_perm,
402+
pub msg_qnum: ::msgqnum_t,
403+
pub msg_qbytes: ::msglen_t,
404+
pub msg_lspid: ::pid_t,
405+
pub msg_lrpid: ::pid_t,
406+
pub msg_stime: ::time_t,
407+
pub msg_rtime: ::time_t,
408+
pub msg_ctime: ::time_t,
409+
}
410+
411+
pub struct ipc_perm {
412+
pub key: ::key_t,
413+
pub uid: ::uid_t,
414+
pub gid: ::gid_t,
415+
pub cuid: ::uid_t,
416+
pub cgid: ::gid_t,
417+
pub mode: ::mode_t,
418+
}
419+
420+
pub struct sembuf {
421+
pub sem_num: ::c_ushort,
422+
pub sem_op: ::c_short,
423+
pub sem_flg: ::c_short,
424+
}
425+
426+
pub struct entry {
427+
pub key: *mut ::c_char,
428+
pub data: *mut ::c_void,
429+
}
387430
}
388431

389432
s_no_extra_traits! {
@@ -657,6 +700,8 @@ pub const PTHREAD_CREATE_DETACHED: ::c_int = 1;
657700

658701
pub const CLOCK_REALTIME: ::c_int = -1;
659702
pub const CLOCK_MONOTONIC: ::c_int = 0;
703+
pub const CLOCK_PROCESS_CPUTIME_ID: ::c_int = -2;
704+
pub const CLOCK_THREAD_CPUTIME_ID: ::c_int = -3;
660705

661706
pub const RLIMIT_CORE: ::c_int = 0;
662707
pub const RLIMIT_CPU: ::c_int = 1;
@@ -665,7 +710,7 @@ pub const RLIMIT_FSIZE: ::c_int = 3;
665710
pub const RLIMIT_NOFILE: ::c_int = 4;
666711
pub const RLIMIT_STACK: ::c_int = 5;
667712
pub const RLIMIT_AS: ::c_int = 6;
668-
pub const RLIM_INFINITY: ::c_ulong = 0xffffffff;
713+
pub const RLIM_INFINITY: ::rlim_t = 0xffffffff;
669714
// Haiku specific
670715
pub const RLIMIT_NOVMON: ::c_int = 7;
671716
pub const RLIM_NLIMITS: ::c_int = 8;
@@ -1564,15 +1609,20 @@ extern "C" {
15641609
bufferSize: ::size_t,
15651610
res: *mut *mut spwd,
15661611
) -> ::c_int;
1567-
}
1568-
1569-
#[link(name = "bsd")]
1570-
extern "C" {
1612+
pub fn mkfifoat(dirfd: ::c_int, pathname: *const ::c_char, mode: ::mode_t) -> ::c_int;
1613+
pub fn mknodat(
1614+
dirfd: ::c_int,
1615+
pathname: *const ::c_char,
1616+
mode: ::mode_t,
1617+
dev: dev_t,
1618+
) -> ::c_int;
15711619
pub fn sem_destroy(sem: *mut sem_t) -> ::c_int;
15721620
pub fn sem_init(sem: *mut sem_t, pshared: ::c_int, value: ::c_uint) -> ::c_int;
15731621

1574-
pub fn clock_gettime(clk_id: ::c_int, tp: *mut ::timespec) -> ::c_int;
1575-
pub fn clock_settime(clk_id: ::c_int, tp: *const ::timespec) -> ::c_int;
1622+
pub fn clock_getres(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int;
1623+
pub fn clock_gettime(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int;
1624+
pub fn clock_settime(clk_id: ::clockid_t, tp: *const ::timespec) -> ::c_int;
1625+
pub fn clock_getcpuclockid(pid: ::pid_t, clk_id: *mut ::clockid_t) -> ::c_int;
15761626
pub fn pthread_create(
15771627
thread: *mut ::pthread_t,
15781628
attr: *const ::pthread_attr_t,
@@ -1600,6 +1650,7 @@ extern "C" {
16001650
pub fn malloc_usable_size(ptr: *mut ::c_void) -> ::size_t;
16011651
pub fn memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void;
16021652
pub fn setgroups(ngroups: ::c_int, ptr: *const ::gid_t) -> ::c_int;
1653+
pub fn initgroups(name: *const ::c_char, basegid: ::gid_t) -> ::c_int;
16031654
pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int;
16041655
pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int) -> ::c_int;
16051656
pub fn dirfd(dirp: *mut ::DIR) -> ::c_int;
@@ -1655,7 +1706,6 @@ extern "C" {
16551706
addrlen: *mut ::socklen_t,
16561707
) -> ::ssize_t;
16571708
pub fn mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int;
1658-
pub fn lutimes(file: *const ::c_char, times: *const ::timeval) -> ::c_int;
16591709
pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char;
16601710

16611711
pub fn bind(socket: ::c_int, address: *const ::sockaddr, address_len: ::socklen_t) -> ::c_int;
@@ -1698,7 +1748,6 @@ extern "C" {
16981748
pub fn getgrnam(name: *const ::c_char) -> *mut ::group;
16991749
pub fn pthread_kill(thread: ::pthread_t, sig: ::c_int) -> ::c_int;
17001750
pub fn sem_unlink(name: *const ::c_char) -> ::c_int;
1701-
pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int;
17021751
pub fn getpwnam_r(
17031752
name: *const ::c_char,
17041753
pwd: *mut passwd,
@@ -1713,6 +1762,14 @@ extern "C" {
17131762
buflen: ::size_t,
17141763
result: *mut *mut passwd,
17151764
) -> ::c_int;
1765+
pub fn getpwent() -> *mut passwd;
1766+
pub fn setpwent();
1767+
pub fn endpwent();
1768+
pub fn endgrent();
1769+
pub fn getgrent() -> *mut ::group;
1770+
pub fn setgrent();
1771+
pub fn setreuid(ruid: ::uid_t, euid: ::uid_t) -> ::c_int;
1772+
pub fn setregid(rgid: ::gid_t, egid: ::gid_t) -> ::c_int;
17161773
pub fn sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int;
17171774
pub fn pthread_atfork(
17181775
prepare: ::Option<unsafe extern "C" fn()>,
@@ -1721,19 +1778,6 @@ extern "C" {
17211778
) -> ::c_int;
17221779
pub fn getgrgid(gid: ::gid_t) -> *mut ::group;
17231780
pub fn popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE;
1724-
pub fn openpty(
1725-
amaster: *mut ::c_int,
1726-
aslave: *mut ::c_int,
1727-
name: *mut ::c_char,
1728-
termp: *mut termios,
1729-
winp: *mut ::winsize,
1730-
) -> ::c_int;
1731-
pub fn forkpty(
1732-
amaster: *mut ::c_int,
1733-
name: *mut ::c_char,
1734-
termp: *mut termios,
1735-
winp: *mut ::winsize,
1736-
) -> ::pid_t;
17371781
pub fn sethostname(name: *const ::c_char, len: ::size_t) -> ::c_int;
17381782
pub fn uname(buf: *mut ::utsname) -> ::c_int;
17391783
pub fn getutxent() -> *mut utmpx;
@@ -1742,31 +1786,126 @@ extern "C" {
17421786
pub fn pututxline(ut: *const utmpx) -> *mut utmpx;
17431787
pub fn setutxent();
17441788
pub fn endutxent();
1789+
pub fn faccessat(
1790+
dirfd: ::c_int,
1791+
pathname: *const ::c_char,
1792+
mode: ::c_int,
1793+
flags: ::c_int,
1794+
) -> ::c_int;
17451795

1746-
pub fn dl_iterate_phdr(
1747-
callback: ::Option<
1748-
unsafe extern "C" fn(
1749-
info: *mut dl_phdr_info,
1750-
size: usize,
1751-
data: *mut ::c_void,
1752-
) -> ::c_int,
1753-
>,
1754-
data: *mut ::c_void,
1796+
pub fn sigtimedwait(
1797+
set: *const sigset_t,
1798+
info: *mut siginfo_t,
1799+
timeout: *const ::timespec,
17551800
) -> ::c_int;
1801+
pub fn sigwaitinfo(set: *const sigset_t, info: *mut siginfo_t) -> ::c_int;
17561802

1757-
pub fn strsep(string: *mut *mut ::c_char, delimiters: *const ::c_char) -> *mut ::c_char;
1758-
pub fn explicit_bzero(buf: *mut ::c_void, len: ::size_t);
1803+
pub fn getitimer(which: ::c_int, curr_value: *mut ::itimerval) -> ::c_int;
1804+
pub fn setitimer(
1805+
which: ::c_int,
1806+
new_value: *const ::itimerval,
1807+
old_value: *mut ::itimerval,
1808+
) -> ::c_int;
17591809

1760-
pub fn login_tty(_fd: ::c_int) -> ::c_int;
1761-
pub fn fgetln(stream: *mut ::FILE, _length: *mut ::size_t) -> *mut ::c_char;
1810+
pub fn regcomp(preg: *mut regex_t, pattern: *const ::c_char, cflags: ::c_int) -> ::c_int;
17621811

1763-
pub fn realhostname(host: *mut ::c_char, hsize: ::size_t, ip: *const in_addr) -> ::c_int;
1764-
pub fn realhostname_sa(
1765-
host: *mut ::c_char,
1766-
hsize: ::size_t,
1767-
addr: *mut sockaddr,
1768-
addrlen: ::c_int,
1812+
pub fn regexec(
1813+
preg: *const regex_t,
1814+
input: *const ::c_char,
1815+
nmatch: ::size_t,
1816+
pmatch: *mut regmatch_t,
1817+
eflags: ::c_int,
17691818
) -> ::c_int;
1819+
1820+
pub fn regerror(
1821+
errcode: ::c_int,
1822+
preg: *const regex_t,
1823+
errbuf: *mut ::c_char,
1824+
errbuf_size: ::size_t,
1825+
) -> ::size_t;
1826+
1827+
pub fn regfree(preg: *mut regex_t);
1828+
1829+
pub fn msgctl(msqid: ::c_int, cmd: ::c_int, buf: *mut msqid_ds) -> ::c_int;
1830+
pub fn msgget(key: ::key_t, msgflg: ::c_int) -> ::c_int;
1831+
pub fn msgrcv(
1832+
msqid: ::c_int,
1833+
msgp: *mut ::c_void,
1834+
msgsz: ::size_t,
1835+
msgtype: ::c_long,
1836+
msgflg: ::c_int,
1837+
) -> ::ssize_t;
1838+
pub fn msgsnd(
1839+
msqid: ::c_int,
1840+
msgp: *const ::c_void,
1841+
msgsz: ::size_t,
1842+
msgflg: ::c_int,
1843+
) -> ::c_int;
1844+
pub fn semget(key: ::key_t, nsems: ::c_int, semflg: ::c_int) -> ::c_int;
1845+
pub fn semctl(semid: ::c_int, semnum: ::c_int, cmd: ::c_int, ...) -> ::c_int;
1846+
pub fn semop(semid: ::c_int, sops: *mut sembuf, nsops: ::size_t) -> ::c_int;
1847+
pub fn ftok(pathname: *const ::c_char, proj_id: ::c_int) -> ::key_t;
1848+
1849+
pub fn memrchr(cx: *const ::c_void, c: ::c_int, n: ::size_t) -> *mut ::c_void;
1850+
1851+
pub fn lsearch(
1852+
key: *const ::c_void,
1853+
base: *mut ::c_void,
1854+
nelp: *mut ::size_t,
1855+
width: ::size_t,
1856+
compar: ::Option<unsafe extern "C" fn(*const ::c_void, *const ::c_void) -> ::c_int>,
1857+
) -> *mut ::c_void;
1858+
pub fn lfind(
1859+
key: *const ::c_void,
1860+
base: *const ::c_void,
1861+
nelp: *mut ::size_t,
1862+
width: ::size_t,
1863+
compar: ::Option<unsafe extern "C" fn(*const ::c_void, *const ::c_void) -> ::c_int>,
1864+
) -> *mut ::c_void;
1865+
pub fn hcreate(nelt: ::size_t) -> ::c_int;
1866+
pub fn hdestroy();
1867+
pub fn hsearch(entry: ::ENTRY, action: ::ACTION) -> *mut ::ENTRY;
1868+
1869+
pub fn drand48() -> ::c_double;
1870+
pub fn erand48(xseed: *mut ::c_ushort) -> ::c_double;
1871+
pub fn lrand48() -> ::c_long;
1872+
pub fn nrand48(xseed: *mut ::c_ushort) -> ::c_long;
1873+
pub fn mrand48() -> ::c_long;
1874+
pub fn jrand48(xseed: *mut ::c_ushort) -> ::c_long;
1875+
pub fn srand48(seed: ::c_long);
1876+
pub fn seed48(xseed: *mut ::c_ushort) -> *mut ::c_ushort;
1877+
pub fn lcong48(p: *mut ::c_ushort);
1878+
1879+
pub fn clearenv() -> ::c_int;
1880+
pub fn ctermid(s: *mut ::c_char) -> *mut ::c_char;
1881+
1882+
pub fn sync();
1883+
pub fn getpagesize() -> ::c_int;
1884+
1885+
pub fn brk(addr: *mut ::c_void) -> ::c_int;
1886+
pub fn sbrk(increment: ::intptr_t) -> *mut ::c_void;
1887+
}
1888+
1889+
#[link(name = "bsd")]
1890+
extern "C" {
1891+
pub fn lutimes(file: *const ::c_char, times: *const ::timeval) -> ::c_int;
1892+
pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int;
1893+
pub fn forkpty(
1894+
amaster: *mut ::c_int,
1895+
name: *mut ::c_char,
1896+
termp: *mut termios,
1897+
winp: *mut ::winsize,
1898+
) -> ::pid_t;
1899+
pub fn openpty(
1900+
amaster: *mut ::c_int,
1901+
aslave: *mut ::c_int,
1902+
name: *mut ::c_char,
1903+
termp: *mut termios,
1904+
winp: *mut ::winsize,
1905+
) -> ::c_int;
1906+
pub fn strsep(string: *mut *mut ::c_char, delimiters: *const ::c_char) -> *mut ::c_char;
1907+
pub fn explicit_bzero(buf: *mut ::c_void, len: ::size_t);
1908+
pub fn login_tty(_fd: ::c_int) -> ::c_int;
17701909
}
17711910

17721911
cfg_if! {

0 commit comments

Comments
 (0)