diff options
author | Sven Gothel <[email protected]> | 2023-01-23 10:17:54 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-01-23 10:17:54 +0100 |
commit | 7e869ec5dde4409bbd3b16253d7c9ad9f3a2d3e7 (patch) | |
tree | 4eaf75d67db83c4a98b376e0132d8674e8e3e463 /src/java/com/jogamp | |
parent | ba93184177af82276c3353ed9759dab8ba0421d7 (diff) |
NativeLibrary: Add getSystemEnvLibraryPaths(), i.e. LD_LIBRARY_PATH, PATH, .. content
Diffstat (limited to 'src/java/com/jogamp')
-rw-r--r-- | src/java/com/jogamp/common/os/NativeLibrary.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/java/com/jogamp/common/os/NativeLibrary.java b/src/java/com/jogamp/common/os/NativeLibrary.java index aa53502..c70c56c 100644 --- a/src/java/com/jogamp/common/os/NativeLibrary.java +++ b/src/java/com/jogamp/common/os/NativeLibrary.java @@ -41,10 +41,12 @@ package com.jogamp.common.os; import java.io.File; +import java.io.IOException; import java.lang.reflect.Method; import java.net.URISyntaxException; import java.security.PrivilegedAction; import java.util.ArrayList; +import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.StringTokenizer; @@ -78,6 +80,7 @@ public final class NativeLibrary implements DynamicLookupHelper { private static final String[] prefixes; private static final String[] suffixes; private static final boolean isOSX; + private static String sys_env_lib_path_varname; static { // Instantiate dynamic linker implementation @@ -85,6 +88,7 @@ public final class NativeLibrary implements DynamicLookupHelper { case WINDOWS: prefixes = new String[] { "" }; suffixes = new String[] { ".dll" }; + sys_env_lib_path_varname = "PATH"; isOSX = false; break; @@ -92,6 +96,7 @@ public final class NativeLibrary implements DynamicLookupHelper { case IOS: prefixes = new String[] { "lib" }; suffixes = new String[] { ".dylib" }; + sys_env_lib_path_varname = "DYLD_LIBRARY_PATH"; isOSX = true; break; @@ -105,6 +110,7 @@ public final class NativeLibrary implements DynamicLookupHelper { default: prefixes = new String[] { "lib" }; suffixes = new String[] { ".so" }; + sys_env_lib_path_varname = "LD_LIBRARY_PATH"; isOSX = false; break; } @@ -138,6 +144,35 @@ public final class NativeLibrary implements DynamicLookupHelper { return "NativeLibrary[" + dynLink.getClass().getSimpleName() + ", " + libraryPath + ", 0x" + Long.toHexString(libraryHandle) + ", global " + global + "]"; } + /** + * Returns the system's environment variable name used for the dynamic linker to resolve library locations, e.g. + * - Windows: PATH + * - MacOS: DYLD_LIBRARY_PATH + * - Unix: LD_LIBRARY_PATH + */ + public static final String getSystemEnvLibraryPathVarname() { return sys_env_lib_path_varname; } + + /** + * Returns a list of system paths, from the {@link #getSystemEnvLibraryPathVarname()} variable. + */ + public static final List<String> getSystemEnvLibraryPaths() { + final String paths = + SecurityUtil.doPrivileged(new PrivilegedAction<String>() { + @Override + public String run() { + return System.getenv(getSystemEnvLibraryPathVarname()); + } + }); + final List<String> res = new ArrayList<String>(); + if( null != paths && paths.length() > 0 ) { + final StringTokenizer st = new StringTokenizer(paths, File.pathSeparator); + while (st.hasMoreTokens()) { + res.add(st.nextToken()); + } + } + return res; + } + /** Opens the given native library, assuming it has the same base name on all platforms. <p> |