2020-04-28 11:53:55 +02:00
|
|
|
module dl
|
|
|
|
|
|
|
|
#include <dlfcn.h>
|
2021-02-23 08:46:28 +01:00
|
|
|
|
2020-04-28 11:53:55 +02:00
|
|
|
pub const (
|
2020-12-15 17:22:07 +01:00
|
|
|
rtld_now = C.RTLD_NOW
|
2020-05-22 17:36:09 +02:00
|
|
|
rtld_lazy = C.RTLD_LAZY
|
2020-04-28 11:53:55 +02:00
|
|
|
)
|
|
|
|
|
2020-04-29 21:01:19 +02: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 11:53:55 +02:00
|
|
|
pub fn open(filename string, flags int) voidptr {
|
2021-03-19 22:27:14 +01:00
|
|
|
return C.dlopen(charptr(filename.str), flags)
|
2020-04-28 11:53:55 +02:00
|
|
|
}
|
|
|
|
|
2020-04-29 21:01:19 +02: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 11:53:55 +02:00
|
|
|
pub fn sym(handle voidptr, symbol string) voidptr {
|
2021-03-19 22:27:14 +01:00
|
|
|
return C.dlsym(handle, charptr(symbol.str))
|
2020-04-28 11:53:55 +02:00
|
|
|
}
|