Skip to content

Commit f1a91da

Browse files
committed
Another round of portability fixes:
* OpenBSD doesn't have idtype_t or the P_* constants either * FreeBSD has different values for the P_* constants * Android gives idtype_t a different signedness * Disable waitid on NetBSD as it causes a link failure - I think this may be a problem with the test environment
1 parent 644929a commit f1a91da

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

src/unix/mod.rs

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,19 @@ pub type cc_t = ::c_uchar;
1616
pub enum DIR {}
1717
pub enum locale_t {}
1818

19-
// FIXME: This is technically wrong; idtype_t is specified as a C enum.
20-
// [ http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_wait.h.html ]
19+
// idtype_t is specified as a C enum:
20+
// http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_wait.h.html
2121
// However, FFI doesn't currently know how to ABI-match a C enum
22-
// (rust#28925, rust#34641) and *probably* the underlying type will be
23-
// c_uint everywhere since all of the enumerators are representable by c_uint.
24-
pub type idtype_t = ::c_uint;
22+
// (rust#28925, rust#34641).
23+
cfg_if! {
24+
if #[cfg(target_os = "openbsd")] {
25+
// idtype_t is not available
26+
} else if #[cfg(target_os = "android")] {
27+
pub type idtype_t = ::c_int;
28+
} else {
29+
pub type idtype_t = ::c_uint;
30+
}
31+
}
2532

2633
s! {
2734
pub struct group {
@@ -210,9 +217,21 @@ pub const PRIO_USER: ::c_int = 2;
210217
pub const PRIO_MIN: ::c_int = -20;
211218
pub const PRIO_MAX: ::c_int = 20;
212219

213-
pub const P_ALL: idtype_t = 0;
214-
pub const P_PID: idtype_t = 1;
215-
pub const P_PGID: idtype_t = 2;
220+
cfg_if! {
221+
if #[cfg(target_os = "openbsd")] {
222+
// P_* constants are not available
223+
} else if #[cfg(target_os = "freebsd")] {
224+
// FreeBSD defines a great many more of these, and gives the
225+
// standardized constants different values from everyone else.
226+
pub const P_PID: idtype_t = 0;
227+
pub const P_PGID: idtype_t = 2;
228+
pub const P_ALL: idtype_t = 7;
229+
} else {
230+
pub const P_ALL: idtype_t = 0;
231+
pub const P_PID: idtype_t = 1;
232+
pub const P_PGID: idtype_t = 2;
233+
}
234+
}
216235

217236
cfg_if! {
218237
if #[cfg(dox)] {
@@ -458,7 +477,7 @@ extern {
458477
link_name = "waitpid$UNIX2003")]
459478
pub fn waitpid(pid: pid_t, status: *mut ::c_int, options: ::c_int)
460479
-> pid_t;
461-
#[cfg(not(target_os = "openbsd"))] // " if " -- appease style checker
480+
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd")))] // " if "
462481
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
463482
link_name = "waitid$UNIX2003")]
464483
pub fn waitid(idtype: idtype_t, id: id_t, infop: *mut ::siginfo_t,

0 commit comments

Comments
 (0)