]> git.mxchange.org Git - simgear.git/blobdiff - simgear/screen/extensions.cxx
Work around a broken dlopen/dlclose Linux implementation.
[simgear.git] / simgear / screen / extensions.cxx
index e6c17ea24e36d9ed3b09974468b87c6615a9ee21..420789eb6aa49e97c23efcdcc076fc08a3a1286a 100644 (file)
 
 #include <string.h>
 
-#ifndef WIN32
-#include <dlfcn.h>
-#else
-#include <windows.h>
-#endif
-
 #include "extensions.hxx"
+#include <simgear/debug/logstream.hxx>
 
-bool SGSearchExtensionsString(char *extString, char *extName) {
+static bool SGSearchExtensionsString(char *extString, char *extName) {
     // Returns GL_TRUE if the *extName string appears in the *extString string,
     // surrounded by white spaces, or GL_FALSE otherwise.
 
     char *p, *end;
     int n, extNameLen;
 
+    if ((extString == NULL) || (extName == NULL))
+        return false;
+
     extNameLen = strlen(extName);
 
     p=extString;
@@ -99,4 +97,30 @@ void* macosxGetGLProcAddress(const char *func) {
   return function;
 }
 
+#else if !defined( WIN32 )
+
+void *SGGetGLProcAddress(const char *func) {
+    static void *libHandle = NULL;
+    void (*fptr)() = NULL;
+
+    /*
+     * Clear the error buffer
+     */
+    dlerror();
+
+    if (libHandle == NULL)
+        libHandle = dlopen("libGL.so", RTLD_LAZY);
+
+    if (libHandle != NULL) {
+        fptr = (void (*)()) dlsym(libHandle, func);
+
+        char *error = dlerror();
+        if (error)
+            SG_LOG(SG_GENERAL, SG_INFO, error);
+    }
+
+    return fptr;
+}
+
 #endif
+