/*
 * Copyright LWJGL. All rights reserved.
 * License terms: http://lwjgl.org/license.php
 */
package org.lwjgl.system.linux;

import org.lwjgl.system.DynamicLinkLibrary;

import java.nio.ByteBuffer;

import static org.lwjgl.system.MemoryUtil.*;
import static org.lwjgl.system.linux.DynamicLinkLoader.*;

/** Implements a {@link DynamicLinkLibrary} on the Linux OS. */
public class LinuxLibrary extends DynamicLinkLibrary.Default {

	private final String name;

	private final long handle;

	public LinuxLibrary(String name) {
		this.name = name;

		long handle = dlopen(name, RTLD_LAZY | RTLD_GLOBAL);
		if ( handle == NULL && name.endsWith(".so") )
			handle = dlopen(name + ".1", RTLD_LAZY | RTLD_GLOBAL);

		if ( handle == NULL ) // TODO: better error handling
			throw new RuntimeException("Failed to dynamically load library: " + name);

		this.handle = handle;
	}

	@Override
	public long getPointer() {
		return handle;
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public long getFunctionAddress(ByteBuffer name) {
		return dlsym(handle, name);
	}

	@Override
	public long getFunctionAddress(CharSequence name) {
		return dlsym(handle, name);
	}

	@Override
	protected void destroy() {
		dlclose(handle);
	}

}
@@ -549,32 +549,80 @@
 %0A%09%09long handle =
+ NULL;%0A%09%09if ( name.endsWith(%22.so%22) )%0A%09%09%09handle =
  dlopen(name, RT
@@ -617,16 +617,23 @@
 pen(name
+ + %22.1%22
 , RTLD_L
@@ -677,32 +677,8 @@
 NULL
- && name.endsWith(%22.so%22)
  )%0A%09
@@ -691,39 +691,32 @@
 le = dlopen(name
- + %22.1%22
 , RTLD_LAZY %7C RT

Load library with .1 postfix first. Fixes #39