Skip to content

Commit 3513dad

Browse files
committed
Allow nix to compile on android
1 parent 274b09e commit 3513dad

File tree

9 files changed

+58
-1
lines changed

9 files changed

+58
-1
lines changed

src/fcntl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ mod consts {
224224
const O_TRUNC = libc::O_TRUNC;
225225
const O_APPEND = libc::O_APPEND;
226226
const O_NONBLOCK = libc::O_NONBLOCK;
227+
#[cfg(target_os = "linux")]
227228
const O_DSYNC = libc::O_DSYNC;
228229
const O_DIRECT = libc::O_DIRECT;
229230
const O_LARGEFILE = 0o00100000;

src/macros.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,22 @@ macro_rules! libc_bitflags {
130130
}
131131
};
132132

133+
// Munch last ident with as
134+
(@accumulate_flags
135+
$prefix:tt,
136+
[$($flags:tt)*];
137+
$flag:ident as $ty:ty
138+
) => {
139+
libc_bitflags! {
140+
@accumulate_flags
141+
$prefix,
142+
[
143+
$($flags)*
144+
const $flag = libc::$flag as $ty;
145+
];
146+
}
147+
};
148+
133149
// Munch an ident; covers terminating comma case.
134150
(@accumulate_flags
135151
$prefix:tt,
@@ -147,6 +163,23 @@ macro_rules! libc_bitflags {
147163
}
148164
};
149165

166+
// Munch an ident; covers terminating comma case with as.
167+
(@accumulate_flags
168+
$prefix:tt,
169+
[$($flags:tt)*];
170+
$flag:ident as $ty:ty, $($tail:tt)*
171+
) => {
172+
libc_bitflags! {
173+
@accumulate_flags
174+
$prefix,
175+
[
176+
$($flags)*
177+
const $flag = libc::$flag as $ty;
178+
];
179+
$($tail)*
180+
}
181+
};
182+
150183
// (non-pub) Entry rule.
151184
(
152185
$(#[$attr:meta])*

src/pty.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ pub fn unlockpt(fd: &PtyMaster) -> Result<()> {
185185
/// the values in `winsize`. If `termios` is not `None`, the pseudoterminal's
186186
/// terminal settings of the slave will be set to the values in `termios`.
187187
#[inline]
188+
#[cfg(not(target_os = "android"))]
188189
pub fn openpty<'a, 'b, T: Into<Option<&'a Winsize>>, U: Into<Option<&'b Termios>>>(winsize: T, termios: U) -> Result<OpenptyResult> {
189190
use std::ptr;
190191

src/sched.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ libc_bitflags!{
2424
CLONE_DETACHED,
2525
CLONE_UNTRACED,
2626
CLONE_CHILD_SETTID,
27+
#[cfg(target_os = "linux")]
2728
CLONE_NEWCGROUP,
2829
CLONE_NEWUTS,
2930
CLONE_NEWIPC,

src/sys/epoll.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ libc_bitflags!(
1717
EPOLLMSG,
1818
EPOLLERR,
1919
EPOLLHUP,
20+
#[cfg(target_os = "linux")]
2021
EPOLLRDHUP,
2122
#[cfg(target_os = "linux")] // Added in 4.5; not in Android.
2223
EPOLLEXCLUSIVE,
2324
#[cfg(not(target_arch = "mips"))]
25+
#[cfg(target_os = "linux")]
2426
EPOLLWAKEUP,
27+
#[cfg(target_os = "linux")]
2528
EPOLLONESHOT,
2629
EPOLLET,
2730
}

src/sys/signal.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ pub const SIGIOT : Signal = SIGABRT;
198198
pub const SIGPOLL : Signal = SIGIO;
199199
pub const SIGUNUSED : Signal = SIGSYS;
200200

201+
#[cfg(not(target_os = "android"))]
201202
libc_bitflags!{
202203
pub flags SaFlags: libc::c_int {
203204
SA_NOCLDSTOP,
@@ -210,6 +211,19 @@ libc_bitflags!{
210211
}
211212
}
212213

214+
#[cfg(target_os = "android")]
215+
libc_bitflags!{
216+
pub flags SaFlags: libc::c_ulong {
217+
SA_NOCLDSTOP as libc::c_ulong,
218+
SA_NOCLDWAIT as libc::c_ulong,
219+
SA_NODEFER as libc::c_ulong,
220+
SA_ONSTACK as libc::c_ulong,
221+
SA_RESETHAND as libc::c_ulong,
222+
SA_RESTART as libc::c_ulong,
223+
SA_SIGINFO as libc::c_ulong,
224+
}
225+
}
226+
213227
#[repr(i32)]
214228
#[derive(Clone, Copy, PartialEq)]
215229
pub enum SigmaskHow {

src/sys/termios.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ mod ffi {
3939
pub use self::non_android::*;
4040

4141
// On Android before 5.0, Bionic directly inline these to ioctl() calls.
42-
#[inline]
4342
#[cfg(all(target_os = "android", not(target_arch = "mips")))]
4443
mod android {
4544
use libc;

src/unistd.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ pub fn daemon(nochdir: bool, noclose: bool) -> Result<()> {
500500
/// On some systems, the host name is limited to as few as 64 bytes. An error
501501
/// will be return if the name is not valid or the current process does not have
502502
/// permissions to update the host name.
503+
#[cfg(not(target_os = "android"))]
503504
pub fn sethostname<S: AsRef<OsStr>>(name: S) -> Result<()> {
504505
// Handle some differences in type of the len arg across platforms.
505506
cfg_if! {
@@ -851,6 +852,7 @@ mod linux {
851852
///
852853
/// Err is returned if the user doesn't have permission to set this UID.
853854
#[inline]
855+
#[cfg(target_os = "linux")]
854856
pub fn setresuid(ruid: uid_t, euid: uid_t, suid: uid_t) -> Result<()> {
855857
let res = unsafe { libc::setresuid(ruid, euid, suid) };
856858

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

test/test_pty.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ fn test_open_ptty_pair() {
9595
}
9696

9797
#[test]
98+
#[cfg(not(target_os = "android"))]
9899
fn test_openpty() {
99100
let pty = openpty(None, None).unwrap();
100101
assert!(pty.master > 0);
@@ -128,6 +129,7 @@ fn test_openpty() {
128129
}
129130

130131
#[test]
132+
#[cfg(not(target_os = "android"))]
131133
fn test_openpty_with_termios() {
132134
// Open one pty to get attributes for the second one
133135
let mut termios = {

0 commit comments

Comments
 (0)