From fcc2094719358f6ac2f2cdf18276f2500eb80253 Mon Sep 17 00:00:00 2001 From: StunxFS <56417208+StunxFS@users.noreply.github.com> Date: Tue, 23 Feb 2021 03:46:28 -0400 Subject: [PATCH] dl: add `get_libname` function (#8909) --- vlib/dl/dl.v | 8 ++++++++ vlib/dl/dl_nix.c.v | 1 + vlib/dl/example/use.v | 2 +- vlib/dl/example/use_test.v | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/vlib/dl/dl.v b/vlib/dl/dl.v index f2cb7e70d4..97ec50e1c4 100644 --- a/vlib/dl/dl.v +++ b/vlib/dl/dl.v @@ -7,6 +7,7 @@ pub const ( // 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 { mut res := '.so' $if macos { @@ -17,3 +18,10 @@ pub fn get_shared_library_extension() string { } return res } + +// 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' +} diff --git a/vlib/dl/dl_nix.c.v b/vlib/dl/dl_nix.c.v index 1f40b8068c..d373ddc2e9 100644 --- a/vlib/dl/dl_nix.c.v +++ b/vlib/dl/dl_nix.c.v @@ -1,6 +1,7 @@ module dl #include + pub const ( rtld_now = C.RTLD_NOW rtld_lazy = C.RTLD_LAZY diff --git a/vlib/dl/example/use.v b/vlib/dl/example/use.v index 600a119d59..82bac72c32 100644 --- a/vlib/dl/example/use.v +++ b/vlib/dl/example/use.v @@ -6,7 +6,7 @@ import dl type FNAdder = fn (int, int) int fn main() { - library_file_path := os.join_path(os.getwd(), 'library$dl.dl_ext') + library_file_path := os.join_path(os.getwd(), dl.get_libname('library')) handle := dl.open(library_file_path, dl.rtld_lazy) eprintln('handle: ${ptr_str(handle)}') mut f := &FNAdder(0) diff --git a/vlib/dl/example/use_test.v b/vlib/dl/example/use_test.v index 7f42fe423c..812281d8a2 100644 --- a/vlib/dl/example/use_test.v +++ b/vlib/dl/example/use_test.v @@ -7,7 +7,7 @@ const ( vexe = os.real_path(os.getenv('VEXE')) cfolder = os.dir(@FILE) so_ext = dl.dl_ext - library_file_name = os.join_path(cfolder, 'library$so_ext') + library_file_name = os.join_path(cfolder, dl.get_libname('library')) ) fn test_vexe() {