@@ -417,12 +417,26 @@ mod tests {
417
417
}
418
418
}
419
419
420
+ // Android with api less than 21 define sig* functions inline, so it is not
421
+ // available for dynamic link. Implementing sigemptyset and sigaddset allow us
422
+ // to support older Android version (independent of libc version).
423
+ // The following implementations are based on https://git.io/vSkNf
424
+
420
425
#[ cfg( not( target_os = "android" ) ) ]
421
426
extern {
427
+ #[ cfg_attr( target_os = "netbsd" , link_name = "__sigemptyset14" ) ]
428
+ fn sigemptyset ( set : * mut libc:: sigset_t ) -> libc:: c_int ;
429
+
422
430
#[ cfg_attr( target_os = "netbsd" , link_name = "__sigaddset14" ) ]
423
431
fn sigaddset ( set : * mut libc:: sigset_t , signum : libc:: c_int ) -> libc:: c_int ;
424
432
}
425
433
434
+ #[ cfg( target_os = "android" ) ]
435
+ unsafe fn sigemptyset ( set : * mut libc:: sigset_t ) -> libc:: c_int {
436
+ libc:: memset ( set as * mut _ , 0 , mem:: size_of :: < libc:: sigset_t > ( ) ) ;
437
+ return 0 ;
438
+ }
439
+
426
440
#[ cfg( target_os = "android" ) ]
427
441
unsafe fn sigaddset ( set : * mut libc:: sigset_t , signum : libc:: c_int ) -> libc:: c_int {
428
442
use slice;
@@ -450,7 +464,7 @@ mod tests {
450
464
451
465
let mut set: libc:: sigset_t = mem:: uninitialized ( ) ;
452
466
let mut old_set: libc:: sigset_t = mem:: uninitialized ( ) ;
453
- t ! ( cvt( libc :: sigemptyset( & mut set) ) ) ;
467
+ t ! ( cvt( sigemptyset( & mut set) ) ) ;
454
468
t ! ( cvt( sigaddset( & mut set, libc:: SIGINT ) ) ) ;
455
469
t ! ( cvt( libc:: pthread_sigmask( libc:: SIG_SETMASK , & set, & mut old_set) ) ) ;
456
470
0 commit comments