org.lwjgl.system.macosx.MacOSXLibraryDL Maven / Gradle / Ivy
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
*/
package org.lwjgl.system.macosx;
import org.lwjgl.system.*;
import java.nio.*;
import static org.lwjgl.system.MemoryStack.*;
import static org.lwjgl.system.MemoryUtil.*;
import static org.lwjgl.system.macosx.DynamicLinkLoader.*;
/** Implements a {@link SharedLibrary} on the macOS using {@link DynamicLinkLoader#dlopen dlopen}. */
public class MacOSXLibraryDL extends MacOSXLibrary {
public MacOSXLibraryDL(String name) {
this(name, loadLibrary(name));
}
public MacOSXLibraryDL(String name, long handle) {
super(name, handle);
}
private static long loadLibrary(String name) {
long handle;
try (MemoryStack stack = stackPush()) {
handle = dlopen(stack.ASCII(name), RTLD_LAZY | RTLD_LOCAL);
}
if (handle == NULL) {
throw new UnsatisfiedLinkError("Failed to dynamically load library: " + name + "(error = " + dlerror() + ")");
}
return handle;
}
@Override
public long getFunctionAddress(ByteBuffer functionName) {
return dlsym(address(), functionName);
}
@Override
public void free() {
dlclose(address());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy