1 /*
2 * Copyright (c) 2013, 2014 Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
1730 }
1731 }
1732
1733 // All native library names we've loaded.
1734 private static Vector<String> loadedLibraryNames = new Vector<>();
1735
1736 // Native libraries belonging to system classes.
1737 private static Vector<NativeLibrary> systemNativeLibraries
1738 = new Vector<>();
1739
1740 // Native libraries associated with the class loader.
1741 private Vector<NativeLibrary> nativeLibraries = new Vector<>();
1742
1743 // native libraries being loaded/unloaded.
1744 private static Stack<NativeLibrary> nativeLibraryContext = new Stack<>();
1745
1746 // The paths searched for libraries
1747 private static String usr_paths[];
1748 private static String sys_paths[];
1749
1750 private static String[] initializePath(String propname) {
1751 String ldpath = System.getProperty(propname, "");
1752 String ps = File.pathSeparator;
1753 int ldlen = ldpath.length();
1754 int i, j, n;
1755 // Count the separators in the path
1756 i = ldpath.indexOf(ps);
1757 n = 0;
1758 while (i >= 0) {
1759 n++;
1760 i = ldpath.indexOf(ps, i + 1);
1761 }
1762
1763 // allocate the array of paths - n :'s = n + 1 path elements
1764 String[] paths = new String[n + 1];
1765
1766 // Fill the array with paths from the ldpath
1767 n = i = 0;
1768 j = ldpath.indexOf(ps);
1769 while (j >= 0) {
1770 if (j - i > 0) {
1771 paths[n++] = ldpath.substring(i, j);
1772 } else if (j - i == 0) {
1773 paths[n++] = ".";
1774 }
1775 i = j + 1;
1776 j = ldpath.indexOf(ps, i);
1777 }
1778 paths[n] = ldpath.substring(i, ldlen);
1779 return paths;
1780 }
1781
1782 // Invoked in the java.lang.Runtime class to implement load and loadLibrary.
1783 static void loadLibrary(Class<?> fromClass, String name,
1784 boolean isAbsolute) {
1785 ClassLoader loader =
1786 (fromClass == null) ? null : fromClass.getClassLoader();
1787 if (sys_paths == null) {
1788 usr_paths = initializePath("java.library.path");
1789 sys_paths = initializePath("sun.boot.library.path");
1790 }
1791 if (isAbsolute) {
1792 if (loadLibrary0(fromClass, new File(name))) {
1793 return;
1794 }
1795 throw new UnsatisfiedLinkError("Can't load library: " + name);
1796 }
1797 if (loader != null) {
1798 String libfilename = loader.findLibrary(name);
|
1 /*
2 * Copyright (c) 2013, 2015 Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
1730 }
1731 }
1732
1733 // All native library names we've loaded.
1734 private static Vector<String> loadedLibraryNames = new Vector<>();
1735
1736 // Native libraries belonging to system classes.
1737 private static Vector<NativeLibrary> systemNativeLibraries
1738 = new Vector<>();
1739
1740 // Native libraries associated with the class loader.
1741 private Vector<NativeLibrary> nativeLibraries = new Vector<>();
1742
1743 // native libraries being loaded/unloaded.
1744 private static Stack<NativeLibrary> nativeLibraryContext = new Stack<>();
1745
1746 // The paths searched for libraries
1747 private static String usr_paths[];
1748 private static String sys_paths[];
1749
1750 private static String[] initializePath(String propName) {
1751 String ldPath = System.getProperty(propName, "");
1752 int ldLen = ldPath.length();
1753 char ps = File.pathSeparatorChar;
1754 boolean mayBeQuoted = ClassLoaderHelper.allowsQuotedPathElements;
1755
1756 int psCount = 0;
1757 boolean inQuotes = false;
1758 boolean thereAreQuotes = false;
1759 for (int i = 0; i < ldLen; ++i) {
1760 char ch = ldPath.charAt(i);
1761 if (mayBeQuoted && ch == '\"') {
1762 inQuotes = !inQuotes;
1763 thereAreQuotes = true;
1764 } else if (!inQuotes && ch == ps) {
1765 psCount++;
1766 }
1767 }
1768
1769 String[] paths = new String[psCount + 1];
1770 if (thereAreQuotes) {
1771 char[] pathBuf = new char[ldLen];
1772 int pathLen = 0;
1773 psCount = 0;
1774 inQuotes = false;
1775 for (int i = 0; i < ldLen; ++i) {
1776 char ch = ldPath.charAt(i);
1777 if (ch == '\"') {
1778 inQuotes = !inQuotes;
1779 } else if (!inQuotes && ch == ps) {
1780 paths[psCount++] = (pathLen > 0) ?
1781 new String(pathBuf, 0, pathLen) : ".";
1782 pathLen = 0;
1783 } else {
1784 pathBuf[pathLen++] = ch;
1785 }
1786 }
1787 paths[psCount] = (pathLen > 0) ?
1788 new String(pathBuf, 0, pathLen) : ".";
1789 } else {
1790 int pathStart = 0;
1791 for (int j = 0; j < psCount; ++j) {
1792 int pathEnd = ldPath.indexOf(ps, pathStart);
1793 paths[j] = (pathStart < pathEnd) ?
1794 ldPath.substring(pathStart, pathEnd) : ".";
1795 pathStart = pathEnd + 1;
1796 }
1797 paths[psCount] = (pathStart < ldLen) ?
1798 ldPath.substring(pathStart, ldLen) : ".";
1799 }
1800 return paths;
1801 }
1802
1803 // Invoked in the java.lang.Runtime class to implement load and loadLibrary.
1804 static void loadLibrary(Class<?> fromClass, String name,
1805 boolean isAbsolute) {
1806 ClassLoader loader =
1807 (fromClass == null) ? null : fromClass.getClassLoader();
1808 if (sys_paths == null) {
1809 usr_paths = initializePath("java.library.path");
1810 sys_paths = initializePath("sun.boot.library.path");
1811 }
1812 if (isAbsolute) {
1813 if (loadLibrary0(fromClass, new File(name))) {
1814 return;
1815 }
1816 throw new UnsatisfiedLinkError("Can't load library: " + name);
1817 }
1818 if (loader != null) {
1819 String libfilename = loader.findLibrary(name);
|