MCPcopy Index your code
hub / github.com/java-native-access/jna / matchLibrary

Method matchLibrary

src/com/sun/jna/NativeLibrary.java:838–876  ·  view source on GitHub ↗

matchLibrary() is very Linux specific. It is here to deal with the case where /usr/lib/libc.so does not exist, or it is not a valid symlink to a versioned file (e.g. /lib/libc.so.6).

(final String libName, Collection<String> searchPath)

Source from the content-addressed store, hash-verified

836 * a versioned file (e.g. /lib/libc.so.6).
837 */
838 static String matchLibrary(final String libName, Collection<String> searchPath) {
839 File lib = new File(libName);
840 if (lib.isAbsolute()) {
841 searchPath = Arrays.asList(lib.getParent());
842 }
843 FilenameFilter filter = new FilenameFilter() {
844 @Override
845 public boolean accept(File dir, String filename) {
846 return (filename.startsWith("lib" + libName + ".so")
847 || (filename.startsWith(libName + ".so")
848 && libName.startsWith("lib")))
849 && isVersionedName(filename);
850 }
851 };
852
853 Collection<File> matches = new LinkedList<>();
854 for (String path : searchPath) {
855 File[] files = new File(path).listFiles(filter);
856 if (files != null && files.length > 0) {
857 matches.addAll(Arrays.asList(files));
858 }
859 }
860
861 //
862 // Search through the results and return the highest numbered version
863 // i.e. libc.so.6 is preferred over libc.so.5
864 double bestVersion = -1;
865 String bestMatch = null;
866 for (File f : matches) {
867 String path = f.getAbsolutePath();
868 String ver = path.substring(path.lastIndexOf(".so.") + 4);
869 double version = parseVersion(ver);
870 if (version > bestVersion) {
871 bestVersion = version;
872 bestMatch = path;
873 }
874 }
875 return bestMatch;
876 }
877
878 static double parseVersion(String ver) {
879 double v = 0;

Callers 3

testAvoidFalseMatchMethod · 0.95
loadLibraryMethod · 0.95

Calls 2

parseVersionMethod · 0.95
getParentMethod · 0.65

Tested by 2

testAvoidFalseMatchMethod · 0.76