2020-04-28 12:53:55 +03:00
|
|
|
module dl
|
|
|
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
|
|
|
pub const (
|
|
|
|
RTLD_NOW = C.RTLD_NOW
|
2020-05-03 18:59:11 +03:00
|
|
|
RTLD_LAZY = C.RTLD_LAZY
|
2020-04-29 22:01:19 +03:00
|
|
|
DL_EXT = '.so'
|
2020-04-28 12:53:55 +03:00
|
|
|
)
|
|
|
|
|
2020-04-29 22:01:19 +03:00
|
|
|
fn C.dlopen(filename charptr, flags int) voidptr
|
|
|
|
|
|
|
|
fn C.dlsym(handle voidptr, symbol charptr) voidptr
|
|
|
|
|
|
|
|
fn C.dlclose(handle voidptr) int
|
|
|
|
|
|
|
|
// open loads the dynamic shared object.
|
2020-04-28 12:53:55 +03:00
|
|
|
pub fn open(filename string, flags int) voidptr {
|
|
|
|
return C.dlopen(filename.str, flags)
|
|
|
|
}
|
|
|
|
|
2020-04-29 22:01:19 +03:00
|
|
|
// close frees a given shared object.
|
|
|
|
pub fn close(handle voidptr) bool {
|
|
|
|
return C.dlclose(handle) == 0
|
|
|
|
}
|
|
|
|
|
|
|
|
// sym returns an address of a symbol in a given shared object.
|
2020-04-28 12:53:55 +03:00
|
|
|
pub fn sym(handle voidptr, symbol string) voidptr {
|
|
|
|
return C.dlsym(handle, symbol.str)
|
|
|
|
}
|