Bug 549771 – improved .gitignore for glib
[platform/upstream/glib.git] / gmodule / gmodule-dl.c
index 9df56d4..035b2a9 100644 (file)
@@ -27,6 +27,7 @@
 /* 
  * MT safe
  */
+#include "config.h"
 
 #include <dlfcn.h>
 
  * RTLD_GLOBAL - the external symbols defined in the library will be made
  *              available to subsequently loaded libraries.
  */
-#ifndef        RTLD_GLOBAL
-#define        RTLD_GLOBAL     0
-#endif /* RTLD_GLOBAL */
 #ifndef        RTLD_LAZY
 #define        RTLD_LAZY       1
 #endif /* RTLD_LAZY */
 #ifndef        RTLD_NOW
 #define        RTLD_NOW        0
 #endif /* RTLD_NOW */
+/* some systems (OSF1 V5.0) have broken RTLD_GLOBAL linkage */
+#ifdef G_MODULE_BROKEN_RTLD_GLOBAL
+#undef RTLD_GLOBAL
+#endif /* G_MODULE_BROKEN_RTLD_GLOBAL */
+#ifndef        RTLD_GLOBAL
+#define        RTLD_GLOBAL     0
+#endif /* RTLD_GLOBAL */
 
 
 /* --- functions --- */
@@ -86,11 +91,13 @@ fetch_dlerror (gboolean replace_null)
 
 static gpointer
 _g_module_open (const gchar *file_name,
-               gboolean     bind_lazy)
+               gboolean     bind_lazy,
+               gboolean     bind_local)
 {
   gpointer handle;
   
-  handle = dlopen (file_name, RTLD_GLOBAL | (bind_lazy ? RTLD_LAZY : RTLD_NOW));
+  handle = dlopen (file_name,
+                  (bind_local ? 0 : RTLD_GLOBAL) | (bind_lazy ? RTLD_LAZY : RTLD_NOW));
   if (!handle)
     g_module_set_error (fetch_dlerror (TRUE));
   
@@ -134,10 +141,13 @@ _g_module_symbol (gpointer     handle,
                  const gchar *symbol_name)
 {
   gpointer p;
-  
+  gchar *msg;
+
+  fetch_dlerror (FALSE);
   p = dlsym (handle, symbol_name);
-  if (!p)
-    g_module_set_error (fetch_dlerror (FALSE));
+  msg = fetch_dlerror (FALSE);
+  if (msg)
+    g_module_set_error (msg);
   
   return p;
 }
@@ -150,9 +160,9 @@ _g_module_build_path (const gchar *directory,
     if (strncmp (module_name, "lib", 3) == 0)
       return g_strconcat (directory, "/", module_name, NULL);
     else
-      return g_strconcat (directory, "/lib", module_name, ".so", NULL);
+      return g_strconcat (directory, "/lib", module_name, "." G_MODULE_SUFFIX, NULL);
   } else if (strncmp (module_name, "lib", 3) == 0)
     return g_strdup (module_name);
   else
-    return g_strconcat ("lib", module_name, ".so", NULL);
+    return g_strconcat ("lib", module_name, "." G_MODULE_SUFFIX, NULL);
 }