Skip to content

Commit

Permalink
Allow nix to compile on android
Browse files Browse the repository at this point in the history
  • Loading branch information
roblabla committed Jun 28, 2017
1 parent 274b09e commit 3513dad
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ mod consts {
const O_TRUNC = libc::O_TRUNC;
const O_APPEND = libc::O_APPEND;
const O_NONBLOCK = libc::O_NONBLOCK;
#[cfg(target_os = "linux")]
const O_DSYNC = libc::O_DSYNC;
const O_DIRECT = libc::O_DIRECT;
const O_LARGEFILE = 0o00100000;
Expand Down
33 changes: 33 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,22 @@ macro_rules! libc_bitflags {
}
};

// Munch last ident with as
(@accumulate_flags
$prefix:tt,
[$($flags:tt)*];
$flag:ident as $ty:ty
) => {
libc_bitflags! {
@accumulate_flags
$prefix,
[
$($flags)*
const $flag = libc::$flag as $ty;
];
}
};

// Munch an ident; covers terminating comma case.
(@accumulate_flags
$prefix:tt,
Expand All @@ -147,6 +163,23 @@ macro_rules! libc_bitflags {
}
};

// Munch an ident; covers terminating comma case with as.
(@accumulate_flags
$prefix:tt,
[$($flags:tt)*];
$flag:ident as $ty:ty, $($tail:tt)*
) => {
libc_bitflags! {
@accumulate_flags
$prefix,
[
$($flags)*
const $flag = libc::$flag as $ty;
];
$($tail)*
}
};

// (non-pub) Entry rule.
(
$(#[$attr:meta])*
Expand Down
1 change: 1 addition & 0 deletions src/pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ pub fn unlockpt(fd: &PtyMaster) -> Result<()> {
/// the values in `winsize`. If `termios` is not `None`, the pseudoterminal's
/// terminal settings of the slave will be set to the values in `termios`.
#[inline]
#[cfg(not(target_os = "android"))]
pub fn openpty<'a, 'b, T: Into<Option<&'a Winsize>>, U: Into<Option<&'b Termios>>>(winsize: T, termios: U) -> Result<OpenptyResult> {
use std::ptr;

Expand Down
1 change: 1 addition & 0 deletions src/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ libc_bitflags!{
CLONE_DETACHED,
CLONE_UNTRACED,
CLONE_CHILD_SETTID,
#[cfg(target_os = "linux")]
CLONE_NEWCGROUP,
CLONE_NEWUTS,
CLONE_NEWIPC,
Expand Down
3 changes: 3 additions & 0 deletions src/sys/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ libc_bitflags!(
EPOLLMSG,
EPOLLERR,
EPOLLHUP,
#[cfg(target_os = "linux")]
EPOLLRDHUP,
#[cfg(target_os = "linux")] // Added in 4.5; not in Android.
EPOLLEXCLUSIVE,
#[cfg(not(target_arch = "mips"))]
#[cfg(target_os = "linux")]
EPOLLWAKEUP,
#[cfg(target_os = "linux")]
EPOLLONESHOT,
EPOLLET,
}
Expand Down
14 changes: 14 additions & 0 deletions src/sys/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ pub const SIGIOT : Signal = SIGABRT;
pub const SIGPOLL : Signal = SIGIO;
pub const SIGUNUSED : Signal = SIGSYS;

#[cfg(not(target_os = "android"))]
libc_bitflags!{
pub flags SaFlags: libc::c_int {
SA_NOCLDSTOP,
Expand All @@ -210,6 +211,19 @@ libc_bitflags!{
}
}

#[cfg(target_os = "android")]
libc_bitflags!{
pub flags SaFlags: libc::c_ulong {
SA_NOCLDSTOP as libc::c_ulong,
SA_NOCLDWAIT as libc::c_ulong,
SA_NODEFER as libc::c_ulong,
SA_ONSTACK as libc::c_ulong,
SA_RESETHAND as libc::c_ulong,
SA_RESTART as libc::c_ulong,
SA_SIGINFO as libc::c_ulong,
}
}

#[repr(i32)]
#[derive(Clone, Copy, PartialEq)]
pub enum SigmaskHow {
Expand Down
1 change: 0 additions & 1 deletion src/sys/termios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ mod ffi {
pub use self::non_android::*;

// On Android before 5.0, Bionic directly inline these to ioctl() calls.
#[inline]
#[cfg(all(target_os = "android", not(target_arch = "mips")))]
mod android {
use libc;
Expand Down
3 changes: 3 additions & 0 deletions src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ pub fn daemon(nochdir: bool, noclose: bool) -> Result<()> {
/// On some systems, the host name is limited to as few as 64 bytes. An error
/// will be return if the name is not valid or the current process does not have
/// permissions to update the host name.
#[cfg(not(target_os = "android"))]
pub fn sethostname<S: AsRef<OsStr>>(name: S) -> Result<()> {
// Handle some differences in type of the len arg across platforms.
cfg_if! {
Expand Down Expand Up @@ -851,6 +852,7 @@ mod linux {
///
/// Err is returned if the user doesn't have permission to set this UID.
#[inline]
#[cfg(target_os = "linux")]
pub fn setresuid(ruid: uid_t, euid: uid_t, suid: uid_t) -> Result<()> {
let res = unsafe { libc::setresuid(ruid, euid, suid) };

Expand All @@ -867,6 +869,7 @@ mod linux {
///
/// Err is returned if the user doesn't have permission to set this GID.
#[inline]
#[cfg(target_os = "linux")]
pub fn setresgid(rgid: gid_t, egid: gid_t, sgid: gid_t) -> Result<()> {
let res = unsafe { libc::setresgid(rgid, egid, sgid) };

Expand Down
2 changes: 2 additions & 0 deletions test/test_pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ fn test_open_ptty_pair() {
}

#[test]
#[cfg(not(target_os = "android"))]
fn test_openpty() {
let pty = openpty(None, None).unwrap();
assert!(pty.master > 0);
Expand Down Expand Up @@ -128,6 +129,7 @@ fn test_openpty() {
}

#[test]
#[cfg(not(target_os = "android"))]
fn test_openpty_with_termios() {
// Open one pty to get attributes for the second one
let mut termios = {
Expand Down

0 comments on commit 3513dad

Please sign in to comment.