Skip to content

Commit 2a93dca

Browse files
committed
Fix build on Android API levels below 21
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.
1 parent 55fb9d8 commit 2a93dca

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/libstd/sys/unix/c.rs

+10
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ extern {
135135
pub fn sigaltstack(ss: *const sigaltstack,
136136
oss: *mut sigaltstack) -> libc::c_int;
137137

138+
#[cfg(not(target_os = "android"))]
138139
pub fn sigemptyset(set: *mut sigset_t) -> libc::c_int;
140+
139141
pub fn pthread_sigmask(how: libc::c_int, set: *const sigset_t,
140142
oldset: *mut sigset_t) -> libc::c_int;
141143

@@ -155,6 +157,14 @@ extern {
155157
-> *mut libc::c_char;
156158
}
157159

160+
// Ugh. This is only available as an inline until Android API 21.
161+
#[cfg(target_os = "android")]
162+
pub unsafe fn sigemptyset(set: *mut sigset_t) -> libc::c_int {
163+
use intrinsics;
164+
intrinsics::write_bytes(set, 0, 1);
165+
return 0;
166+
}
167+
158168
#[cfg(any(target_os = "linux",
159169
target_os = "android"))]
160170
mod signal_os {

src/libstd/sys/unix/process.rs

+10
Original file line numberDiff line numberDiff line change
@@ -446,12 +446,22 @@ mod tests {
446446
use mem;
447447
use ptr;
448448
use libc;
449+
use slice;
449450
use sys::{self, c, cvt, pipe};
450451

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

457+
#[cfg(target_os = "android")]
458+
unsafe fn sigaddset(set: *mut c::sigset_t, signum: libc::c_int) -> libc::c_int {
459+
let raw = slice::from_raw_parts_mut(set as *mut u8, mem::size_of::<c::sigset_t>());
460+
let bit = (signum - 1) as usize;
461+
raw[bit / 8] |= 1 << (bit % 8);
462+
return 0;
463+
}
464+
455465
#[test]
456466
fn test_process_mask() {
457467
unsafe {

0 commit comments

Comments
 (0)