aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/old/vlib/dl/dl_nix.c.v
blob: 40f63b542c8fefc7eb4100a11a4e66a36b1de857 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module dl

#include <dlfcn.h>

$if linux {
	#flag -ldl
}

pub const (
	rtld_now  = C.RTLD_NOW
	rtld_lazy = C.RTLD_LAZY
)

fn C.dlopen(filename &char, flags int) voidptr

fn C.dlsym(handle voidptr, symbol &char) voidptr

fn C.dlclose(handle voidptr) int

fn C.dlerror() &char

// open loads the dynamic shared object.
pub fn open(filename string, flags int) voidptr {
	return C.dlopen(&char(filename.str), flags)
}

// 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.
pub fn sym(handle voidptr, symbol string) voidptr {
	return C.dlsym(handle, &char(symbol.str))
}

// dlerror provides a text error diagnostic message for functions in `dl`
// it returns a human-readable string, describing the most recent error
// that occurred from a call to one of the `dl` functions, since the last
// call to dlerror()
pub fn dlerror() string {
	return unsafe { cstring_to_vstring(C.dlerror()) }
}