Skip to content

Commit

Permalink
Fix build on Android API levels below 21
Browse files Browse the repository at this point in the history
signal(), sigemptyset(), and sigaddset() are only available as inline
functions until Android API 21. liblibc already handles signal()
appropriately, so drop it from c.rs; translate sigemptyset() and
sigaddset() (which is only used in a test) by hand from the C inlines.

We probably want to revert this commit when we bump Android API level.
  • Loading branch information
geofft committed Jun 20, 2015
1 parent 55fb9d8 commit 2a93dca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/libstd/sys/unix/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ extern {
pub fn sigaltstack(ss: *const sigaltstack,
oss: *mut sigaltstack) -> libc::c_int;

#[cfg(not(target_os = "android"))]
pub fn sigemptyset(set: *mut sigset_t) -> libc::c_int;

pub fn pthread_sigmask(how: libc::c_int, set: *const sigset_t,
oldset: *mut sigset_t) -> libc::c_int;

Expand All @@ -155,6 +157,14 @@ extern {
-> *mut libc::c_char;
}

// Ugh. This is only available as an inline until Android API 21.
#[cfg(target_os = "android")]
pub unsafe fn sigemptyset(set: *mut sigset_t) -> libc::c_int {
use intrinsics;
intrinsics::write_bytes(set, 0, 1);
return 0;
}

#[cfg(any(target_os = "linux",
target_os = "android"))]
mod signal_os {
Expand Down
10 changes: 10 additions & 0 deletions src/libstd/sys/unix/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,22 @@ mod tests {
use mem;
use ptr;
use libc;
use slice;
use sys::{self, c, cvt, pipe};

#[cfg(not(target_os = "android"))]
extern {
fn sigaddset(set: *mut c::sigset_t, signum: libc::c_int) -> libc::c_int;
}

#[cfg(target_os = "android")]
unsafe fn sigaddset(set: *mut c::sigset_t, signum: libc::c_int) -> libc::c_int {
let raw = slice::from_raw_parts_mut(set as *mut u8, mem::size_of::<c::sigset_t>());
let bit = (signum - 1) as usize;
raw[bit / 8] |= 1 << (bit % 8);
return 0;
}

#[test]
fn test_process_mask() {
unsafe {
Expand Down

0 comments on commit 2a93dca

Please sign in to comment.