about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
authorGeoffrey Thomas <geofft@ldpreload.com>2015-06-11 16:23:57 -0400
committerGeoffrey Thomas <geofft@ldpreload.com>2015-06-22 00:55:42 -0400
commita8dbb92b471cae1d3f8225857f5553311dd8aeb3 (patch)
treefc42147eab5e968a570e22f83adbd35fae7937d4 /src/libstd/sys
parentcae005162d1d7aea6cffdc299fedf0d2bb2a4b28 (diff)
downloadrust-a8dbb92b471cae1d3f8225857f5553311dd8aeb3.tar.gz
rust-a8dbb92b471cae1d3f8225857f5553311dd8aeb3.zip
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.
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/unix/c.rs10
-rw-r--r--src/libstd/sys/unix/process.rs10
2 files changed, 20 insertions, 0 deletions
diff --git a/src/libstd/sys/unix/c.rs b/src/libstd/sys/unix/c.rs
index 431312b3d8f..99a6731c57d 100644
--- a/src/libstd/sys/unix/c.rs
+++ b/src/libstd/sys/unix/c.rs
@@ -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;
 
@@ -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 {
diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs
index 85ce8d79880..695d0ddfaaf 100644
--- a/src/libstd/sys/unix/process.rs
+++ b/src/libstd/sys/unix/process.rs
@@ -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 {