diff options
author | Indrajith K L | 2022-12-03 17:00:20 +0530 |
---|---|---|
committer | Indrajith K L | 2022-12-03 17:00:20 +0530 |
commit | f5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch) | |
tree | 2764fc62da58f2ba8da7ed341643fc359873142f /v_windows/v/old/vlib/dl/dl.v | |
download | cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.gz cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.bz2 cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.zip |
Diffstat (limited to 'v_windows/v/old/vlib/dl/dl.v')
-rw-r--r-- | v_windows/v/old/vlib/dl/dl.v | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/v_windows/v/old/vlib/dl/dl.v b/v_windows/v/old/vlib/dl/dl.v new file mode 100644 index 0000000..04ad16b --- /dev/null +++ b/v_windows/v/old/vlib/dl/dl.v @@ -0,0 +1,48 @@ +module dl + +pub const ( + version = 1 + dl_ext = get_shared_library_extension() +) + +// get_shared_library_extension returns the platform dependent shared library extension +// i.e. .dll on windows, .so on most unixes, .dylib on macos. +[inline] +pub fn get_shared_library_extension() string { + return $if windows { + '.dll' + } $else $if macos { + '.dylib' + } $else { + '.so' + } +} + +// get_libname returns a library name with the operating system specific extension for +// shared libraries. +[inline] +pub fn get_libname(libname string) string { + return '$libname$dl.dl_ext' +} + +// open_opt - loads the dynamic shared object. +// Unlike open, open_opt return an option. +pub fn open_opt(filename string, flags int) ?voidptr { + shared_object_handle := open(filename, flags) + if shared_object_handle == 0 { + e := dlerror() + return error(e) + } + return shared_object_handle +} + +// sym_opt returns the address of a symbol in a given shared object, if found. +// Unlike sym, sym_opt returns an option. +pub fn sym_opt(shared_object_handle voidptr, symbol string) ?voidptr { + sym_handle := sym(shared_object_handle, symbol) + if sym_handle == 0 { + e := dlerror() + return error(e) + } + return sym_handle +} |