@@ -4,15 +4,8 @@ pub use self::platform::Library;
44
55#[ cfg( unix) ]
66mod platform {
7- use std:: ffi:: { CStr , c_char, c_int, c_void} ;
8-
9- #[ link( name="dl" ) ]
10- extern "C" {
11- fn dlopen ( filename : * const i8 , flag : c_int ) -> * mut c_void ;
12- fn dlsym ( handle : * mut c_void , symbol : * const i8 ) -> * mut c_void ;
13- fn dlclose ( handle : * mut c_void ) -> c_int ;
14- fn dlerror ( ) -> * const c_char ;
15- }
7+ use std:: ffi:: { CStr , c_void} ;
8+ use libc:: { c_char, RTLD_NOW } ;
169
1710 pub struct Library ( * mut c_void ) ;
1811
@@ -21,8 +14,8 @@ mod platform {
2114
2215 impl Library {
2316 pub unsafe fn open ( path : & CStr ) -> Result < Self , String > {
24- const RTLD_NOW : c_int = 2 ;
25- let handle = dlopen ( path. as_ptr ( ) , RTLD_NOW ) ;
17+ use libc :: dlopen ;
18+ let handle = dlopen ( path. as_ptr ( ) as * const c_char , RTLD_NOW ) ;
2619 if handle. is_null ( ) {
2720 Self :: error ( )
2821 }
@@ -32,7 +25,8 @@ mod platform {
3225 }
3326
3427 pub unsafe fn get ( & self , sym : & CStr ) -> Result < * mut ( ) , String > {
35- let ptr = dlsym ( self . 0 , sym. as_ptr ( ) ) ;
28+ use libc:: dlsym;
29+ let ptr = dlsym ( self . 0 , sym. as_ptr ( ) as * const c_char ) ;
3630 if ptr. is_null ( ) {
3731 Self :: error ( )
3832 }
@@ -42,6 +36,7 @@ mod platform {
4236 }
4337
4438 unsafe fn error < T > ( ) -> Result < T , String > {
39+ use libc:: dlerror;
4540 let cstr = dlerror ( ) ;
4641 let cstr = CStr :: from_ptr ( cstr) ;
4742 let string = cstr. to_str ( )
@@ -53,7 +48,9 @@ mod platform {
5348
5449 impl Drop for Library {
5550 fn drop ( & mut self ) {
56- unsafe { dlclose ( self . 0 ) ; }
51+ unsafe {
52+ libc:: dlclose ( self . 0 ) ;
53+ }
5754 }
5855 }
5956}
@@ -62,11 +59,12 @@ mod platform {
6259mod platform {
6360 use std:: ffi:: { CStr , OsString , c_void} ;
6461 use std:: os:: windows:: ffi:: OsStrExt ;
62+ use libc:: c_char;
6563
6664 #[ link( name="kernel32" ) ]
6765 extern "system" {
6866 fn LoadLibraryW ( lpLibFileName : * const u16 ) -> * mut c_void ;
69- fn GetProcAddress ( hModule : * mut c_void , lpProcName : * const u8 ) -> * mut c_void ;
67+ fn GetProcAddress ( hModule : * mut c_void , lpProcName : * const c_char ) -> * mut c_void ;
7068 fn FreeLibrary ( hLibModule : * mut c_void ) ;
7169 }
7270
@@ -90,7 +88,7 @@ mod platform {
9088 }
9189
9290 pub unsafe fn get ( & self , sym : & CStr ) -> Result < * mut ( ) , String > {
93- let ptr = GetProcAddress ( self . 0 , sym. as_ptr ( ) as * const _ ) ;
91+ let ptr = GetProcAddress ( self . 0 , sym. as_ptr ( ) as * const c_char ) ;
9492 if ptr. is_null ( ) {
9593 Err ( "cannot load symbol" . to_string ( ) )
9694 }
0 commit comments