38static bool existsPath(
const std::string& libPath)
noexcept {
40 return path_stats.
exists();
42static bool existsLibBasename(
const std::string& libBasename,
const std::string& relDir, std::string& libPath)
noexcept {
63 const std::string libBasename =
"testlib";
67 const std::string symbolName =
"jaulib_id_entryfunc";
70 std::cout <<
"Warning: library '" << libBasename <<
"' doesn't exist at: build '" << libPathBuild <<
"', nor at orig '" << libPathOrig <<
"'" << std::endl;
79 const std::string libDirOrig = libDir +
"/orig";
82 std::cout <<
"remove: " << libDirOrig << std::endl;
91 std::cout <<
"move: libs in '" << libDir <<
"' to '" << libDirOrig <<
"'" << std::endl;
94 std::cout <<
"- move: ignore entry depth[" << depth <<
"]" << element_stats.item().to_string() << std::endl;
98 std::string bname = element_stats.item().basename();
99 if( 0 == bname.find(libName) ) {
100 const std::string p = libDirOrig +
"/" + bname;
101 std::cout <<
"- move: depth[" << depth <<
"]: '" << element_stats.path() <<
"' to '" << p <<
"'" << std::endl;
109 std::cout <<
"post move: " << path_stats2.
to_string() << std::endl;
122 const std::string libBasenameCopy =
"testlib2";
128 std::cout <<
"remove: " << libDirCopy << std::endl;
133 const std::string libPathCopy = libDirCopy +
"/" + libNameCopy;
134 REQUIRE(
true ==
jau::fs::copy(libPathOrigFile, libPathCopy, copts) );
136 std::string libPath2;
142 const std::string symbolName =
"jaulib_id_entryfunc";
144 std::cout <<
"- libBasename: " << libBasename << std::endl;
145 std::cout <<
"- libName: " << libName << std::endl;
152 std::cout <<
"Warning: library '" << libName <<
"' doesn't exist at: '" << libPath <<
"'" << std::endl;
158 std::cout <<
"- Path: " << libPath << std::endl;
160 REQUIRE(
nullptr != libHandle );
163 std::cout <<
"- Symbol '" << symbolName <<
"': Handle = " <<
jau::to_hexstring(symHandle) << std::endl;
164 REQUIRE(
nullptr != symHandle );
167 if(
nullptr == nativePath ) {
168 std::cout <<
"- Native Path: null" << std::endl;
170 std::cout <<
"- Native Path: '" << std::string(nativePath) <<
"'" << std::endl;
172 REQUIRE(
nullptr != nativePath );
176 std::cout <<
"- Basename (path): " << bname1 << std::endl;
177 REQUIRE( libBasename == bname1 );
178 if(
nullptr != nativePath ) {
180 std::cout <<
"- Basename (native-path): " << bname2 << std::endl;
181 REQUIRE( libBasename == bname2 );
192 std::cout <<
"- lib_path_var_name: " << lib_path_var_name << std::endl;
193 std::cout <<
"- lib_path_var : " << lib_path_var << std::endl;
194 std::cout <<
"- lib_paths: count : " << lib_paths.size() << std::endl <<
" - path: ";
195 std::cout <<
jau::to_string(lib_paths,
"\n - path: ") << std::endl;
202 const std::string symbolName =
"jaulib_id_entryfunc";
204 std::cout <<
"- libBasename: " << libBasename << std::endl;
205 std::cout <<
"- libName: " << libName << std::endl;
209 const std::string libPathRel = libDirRel +
"/" + libName;
210 std::string libDirAbs, libPathAbs;
212 std::cout <<
"- cwd: " << cwd << std::endl;
214 std::cout <<
"- exe-abs " << exe_path_abs << std::endl << std::endl;
217 REQUIRE(
true == fs.
exists() );
220 libPathAbs = libDirAbs +
"/" + libName;
223 std::cout <<
"Warning: library '" << libName <<
"' doesn't exist at: '" << libPathAbs <<
"'" << std::endl;
230 std::cout <<
"Sys-Path: '" << lib_path_var_name <<
"': Original" << std::endl;
232 std::cout <<
"- lib_path_var (1) : " << lib_path_var0 << std::endl;
233 std::cout <<
"- lib_paths: count : " << lib_paths1.size() << std::endl <<
" - path: '";
234 std::cout <<
jau::to_string(lib_paths1,
"'\n - path: '") <<
"'" << std::endl;
240 const bool searchSystemPath =
false;
241 const bool searchSystemPathFirst =
false;
242 const bool global =
false;
243 std::cout <<
"Check-1: Absolute Path: '" << libPathAbs <<
"', cwd2 '" << cwd2 <<
"'" << std::endl;
245 std::cout <<
"Check-1: " << nl.
toString() << std::endl;
246 REQUIRE(
true == nl.
isValid() );
247 REQUIRE(
true == nl.
isOpen() );
249 REQUIRE(
false == nl.
isOpen() );
250 REQUIRE(
true == nl.
isValid() );
258 const bool searchSystemPath =
false;
259 const bool searchSystemPathFirst =
false;
260 const bool global =
false;
261 std::cout <<
"Check-2: Relative Path to cwd: libPathRel '" << libPathRel <<
"', cwd2 '" << cwd2 <<
"'" << std::endl;
263 std::cout <<
"Check-2: " << nl.
toString() << std::endl;
264 REQUIRE(
true == nl.
isValid() );
265 REQUIRE(
true == nl.
isOpen() );
267 REQUIRE(
false == nl.
isOpen() );
268 REQUIRE(
true == nl.
isValid() );
275 std::cout <<
"Sys-Path: '" << lib_path_var_name <<
"': Variant 1: With libDirAbs" << std::endl;
276 std::string lib_path_var2;
277 if( lib_path_var0.size() > 0 ) {
280 lib_path_var2 = libDirAbs;
282 ::setenv(lib_path_var_name.c_str(), lib_path_var2.c_str(), 1 );
283 std::cout <<
"- lib_path_var set 2: " << lib_path_var2 << std::endl;
287 std::cout <<
"- lib_path_var get 2: " << lib_path_var << std::endl;
288 std::cout <<
"- lib_paths: count : " << lib_paths.size() << std::endl <<
" - path: '";
289 std::cout <<
jau::to_string(lib_paths,
"'\n - path: '") <<
"'" << std::endl;
294 const bool searchSystemPath =
true;
295 const bool searchSystemPathFirst =
true;
296 const bool global =
false;
299 std::cout <<
"Check-10: libBasename in sys: '" << libBasename <<
"', cwd2 '" << cwd2 <<
"'" << std::endl;
301 std::cout <<
"Check-10: " << nl.
toString() << std::endl;
302 REQUIRE(
true == nl.
isValid() );
303 REQUIRE(
true == nl.
isOpen() );
305 REQUIRE(
false == nl.
isOpen() );
306 REQUIRE(
true == nl.
isValid() );
310 std::cout <<
"Check-11: libName in sys: '" << libName <<
"', cwd2 '" << cwd2 <<
"'" << std::endl;
312 std::cout <<
"Check-11: " << nl.
toString() << std::endl;
313 REQUIRE(
true == nl.
isValid() );
314 REQUIRE(
true == nl.
isOpen() );
316 REQUIRE(
false == nl.
isOpen() );
317 REQUIRE(
true == nl.
isValid() );
323 std::cout <<
"Sys-Path: '" << lib_path_var_name <<
"': Variant 2: With test_exe path" << std::endl;
324 std::string lib_path_var2;
325 if( lib_path_var0.size() > 0 ) {
328 lib_path_var2 = exe_dir;
330 ::setenv(lib_path_var_name.c_str(), lib_path_var2.c_str(), 1 );
331 std::cout <<
"- lib_path_var set 3: " << lib_path_var2 << std::endl;
335 std::cout <<
"- lib_path_var get 3: " << lib_path_var << std::endl;
336 std::cout <<
"- lib_paths: count : " << lib_paths.size() << std::endl <<
" - path: '";
337 std::cout <<
jau::to_string(lib_paths,
"'\n - path: '") <<
"'" << std::endl;
343 const bool searchSystemPath =
true;
344 const bool searchSystemPathFirst =
true;
345 const bool global =
true;
346 std::cout <<
"Check-12: Relative Path to cwd: " << libPathRel << std::endl;
348 std::cout <<
"Check-12: " << nl.
toString() << std::endl;
349 REQUIRE(
true == nl.
isValid() );
350 REQUIRE(
true == nl.
isOpen() );
352 REQUIRE(
false == nl.
isOpen() );
353 REQUIRE(
true == nl.
isValid() );
359TEST_CASE(
"Test10",
"[orig][NativeLibrary][dll][os]" ) {
364TEST_CASE(
"Test11",
"[copy][NativeLibrary][dll][os]" ) {
std::string executable_path
The main argv[0] test executable path.
static std::string getProperty(const std::string &name) noexcept
Returns the value of the environment's variable 'name'.
Platform agnostic representation of POSIX ::lstat() and ::stat() for a given pathname.
constexpr bool exists() const noexcept
Returns true if entity does not exist, exclusive bit.
const file_stats * final_target(size_t *link_count=nullptr) const noexcept
Returns the final target element, either a pointer to this instance if not a symbolic-link or the fin...
std::string to_string() const noexcept
Returns a comprehensive string representation of this element.
std::string path() const noexcept
Returns the unix path representation.
Class template jau::function is a general-purpose static-polymorphic function wrapper.
Low level secure dynamic linker access.
static std::string getBaseName(const std::string &filename, const bool isBasename=false, const bool caseInsensitive=jau::os::is_windows()) noexcept
Returns the library basename, i.e.
static DynamicLinker & get() noexcept
Returns static singleton instance of DynamicLinker.
symhandle_t lookupSymbol(libhandle_t handle, const std::string &symbolName) noexcept
void * symhandle_t
symbol handle within a library
static constexpr_cxx20 std::string getEnvLibPathVarName() noexcept
Returns the environment library path variable name, e.g.
void * libhandle_t
library handle
const char * lookupLibraryPathname(libhandle_t handle, const std::string &symbolName) noexcept
static constexpr_cxx20 std::string getCanonicalName(const std::string &basename, const bool checkIsCanonical=true) noexcept
Returns canonical library name for this system from given library-basename, e.g.
libhandle_t openLibraryLocal(const std::string &pathname) noexcept
Opens the named library, restricting access to this process.
static std::vector< std::string > getSystemEnvLibraryPaths()
Returns a list of system paths, from the getSystemEnvLibraryPathVarname() variable.
Runtime libary dynamic library (RTLD) access.
bool isValid() const noexcept
Returns true if this instance is valid, i.e.
void close() noexcept
Closes this native library.
std::string toString() const noexcept
bool isOpen() const noexcept
Returns true if this instance isValid() and not close()'ed, otherwise false.
static NativeLibrary open(const std::string &libName, const bool searchSystemPath, const bool searchSystemPathFirst, const bool global) noexcept
Opens the given native library, assuming it has the same base name on all platforms.
std::string to_string(const endian_t v) noexcept
Return std::string representation of the given endian.
bool mkdir(const std::string &path, const fmode_t mode=jau::fs::fmode_t::def_dir_prot, const bool verbose=false) noexcept
Create directory.
bool copy(const std::string &source_path, const std::string &dest_path, const copy_options copts=copy_options::none) noexcept
Copy the given source_path to dest_path using copy_options.
std::string get_cwd() noexcept
Return the current working directory or empty on failure.
bool visit(const std::string &path, const traverse_options topts, const path_visitor &visitor, std::vector< int > *dirfds=nullptr) noexcept
Visit element(s) of a given path, see traverse_options for detailed settings.
std::string absolute(const std::string_view &relpath) noexcept
Returns the absolute path of given relpath if existing, otherwise an empty string.
std::string dirname(const std::string_view &path) noexcept
Return stripped last component from given path separated by /, excluding the trailing separator /.
copy_options
Filesystem copy options used to copy() path elements.
traverse_options
Filesystem traverse options used to visit() path elements.
bool rename(const std::string &oldpath, const std::string &newpath) noexcept
Rename oldpath to newpath using POSIX rename(), with the following combinations.
bool remove(const std::string &path, const traverse_options topts=traverse_options::none) noexcept
Remove the given path.
constexpr bool is_set(const fmode_t mask, const fmode_t bits) noexcept
bool chdir(const std::string &path) noexcept
Change working directory.
traverse_event
Filesystem traverse event used to call path_visitor for path elements from visit().
@ def_dir_prot
Default directory protection bit: Safe default: POSIX S_IRWXU | S_IRGRP | S_IXGRP or rwx_usr | read_g...
@ verbose
Enable verbosity mode, show error messages on stderr.
@ overwrite
Overwrite existing destination files.
@ preserve_all
Preserve uid and gid if allowed and access- and modification-timestamps, i.e.
@ verbose
Enable verbosity mode, potentially used by a path_visitor implementation like remove().
@ dir_check_entry
Call path_visitor at directory entry, allowing path_visitor to skip traversal of this directory if re...
@ recursive
Traverse through directories, i.e.
@ none
No value, neither file, symlink nor dir_entry or dir_exit.
@ file
Visiting a file, may be in conjunction with symlink, i.e.
@ dir_check_entry
Visiting a directory on entry, see traverse_options::dir_check_entry.
@ symlink
Visiting a symbolic-link, either to a file or a non-existing entity.
constexpr_cxx20 std::string path_separator() noexcept
Returns the OS's path separator as a string, e.g.
std::string to_hexstring(value_type const &v) noexcept
Produce a lower-case hexadecimal string representation of the given pointer.
static bool existsLibBasename(const std::string &libBasename, const std::string &relDir, std::string &libPath) noexcept
void test10NativeLibrary(const std::string &libBasename, const std::string &libDirRel)
TEST_CASE("Test00", "[dll][os]")
void test01DynamikLinkerAbs(const std::string &libBasename, const std::string &relDir)
static bool existsPath(const std::string &libPath) noexcept