File tree Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Original file line number Diff line number Diff line change
1
+ use std:: mem;
1
2
use libc:: { c_int, c_uint} ;
2
3
use fcntl:: Fd ;
3
4
use errno:: { SysResult , SysError , from_ffi} ;
4
5
5
- mod ffi {
6
- use libc:: { c_int, c_uint} ;
7
-
8
- extern {
9
- pub fn eventfd ( initval : c_uint , flags : c_int ) -> c_int ;
10
- }
11
- }
12
-
13
6
bitflags ! (
14
7
flags EventFdFlag : c_int {
15
8
static EFD_CLOEXEC = 0o2000000 , // Since Linux 2.6.27
@@ -19,7 +12,21 @@ bitflags!(
19
12
)
20
13
21
14
pub fn eventfd ( initval : uint , flags : EventFdFlag ) -> SysResult < Fd > {
22
- let res = unsafe { ffi:: eventfd ( initval as c_uint , flags. bits ( ) ) } ;
15
+ type F = unsafe extern "C" fn ( initval : c_uint , flags : c_int ) -> c_int ;
16
+
17
+ extern {
18
+ #[ linkage = "extern_weak" ]
19
+ static eventfd: * const ( ) ;
20
+ }
21
+
22
+ if eventfd. is_null ( ) {
23
+ fail ! ( "eventfd unsupported on this platform" ) ;
24
+ }
25
+
26
+ let res = unsafe {
27
+ mem:: transmute :: < * const ( ) , F > ( eventfd) (
28
+ initval as c_uint , flags. bits ( ) )
29
+ } ;
23
30
24
31
if res < 0 {
25
32
return Err ( SysError :: last ( ) ) ;
You can’t perform that action at this time.
0 commit comments