diff options
author | Zack Weinberg <zackw@panix.com> | 2017-01-06 18:55:32 -0500 |
---|---|---|
committer | Zack Weinberg <zackw@panix.com> | 2017-01-06 18:55:32 -0500 |
commit | f1a91da7aa3127184a43dd3889af2f0ac3baf9e8 (patch) | |
tree | a9bacafaae7a011df4707fde156481ac8980bc8c | |
parent | 644929ad10a2c82911a34c7581b53234c7224ad7 (diff) | |
download | rust-libc-f1a91da7aa3127184a43dd3889af2f0ac3baf9e8.tar.gz |
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
-rw-r--r-- | src/unix/mod.rs | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 8315151b81..e0cf1463f4 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -16,12 +16,19 @@ pub type cc_t = ::c_uchar; pub enum DIR {} pub enum locale_t {} -// FIXME: This is technically wrong; idtype_t is specified as a C enum. -// [ http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_wait.h.html ] +// idtype_t is specified as a C enum: +// http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_wait.h.html // However, FFI doesn't currently know how to ABI-match a C enum -// (rust#28925, rust#34641) and *probably* the underlying type will be -// c_uint everywhere since all of the enumerators are representable by c_uint. -pub type idtype_t = ::c_uint; +// (rust#28925, rust#34641). +cfg_if! { + if #[cfg(target_os = "openbsd")] { + // idtype_t is not available + } else if #[cfg(target_os = "android")] { + pub type idtype_t = ::c_int; + } else { + pub type idtype_t = ::c_uint; + } +} s! { pub struct group { @@ -210,9 +217,21 @@ pub const PRIO_USER: ::c_int = 2; pub const PRIO_MIN: ::c_int = -20; pub const PRIO_MAX: ::c_int = 20; -pub const P_ALL: idtype_t = 0; -pub const P_PID: idtype_t = 1; -pub const P_PGID: idtype_t = 2; +cfg_if! { + if #[cfg(target_os = "openbsd")] { + // P_* constants are not available + } else if #[cfg(target_os = "freebsd")] { + // FreeBSD defines a great many more of these, and gives the + // standardized constants different values from everyone else. + pub const P_PID: idtype_t = 0; + pub const P_PGID: idtype_t = 2; + pub const P_ALL: idtype_t = 7; + } else { + pub const P_ALL: idtype_t = 0; + pub const P_PID: idtype_t = 1; + pub const P_PGID: idtype_t = 2; + } +} cfg_if! { if #[cfg(dox)] { @@ -458,7 +477,7 @@ extern { link_name = "waitpid$UNIX2003")] pub fn waitpid(pid: pid_t, status: *mut ::c_int, options: ::c_int) -> pid_t; - #[cfg(not(target_os = "openbsd"))] // " if " -- appease style checker + #[cfg(not(any(target_os = "openbsd", target_os = "netbsd")))] // " if " #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "waitid$UNIX2003")] pub fn waitid(idtype: idtype_t, id: id_t, infop: *mut ::siginfo_t, |