Main Page | Class List | Directories | File List | Class Members | File Members

gmodule-dl.c File Reference

#include <dlfcn.h>

Go to the source code of this file.

Defines

#define dlerror()   "unknown dl-error"
#define RTLD_LAZY   1
#define RTLD_NOW   0
#define RTLD_GLOBAL   0

Functions

static gcharfetch_dlerror (void)
static gpointer _g_module_open (const gchar *file_name, gboolean bind_lazy)
static gpointer _g_module_self (void)
static void _g_module_close (gpointer handle, gboolean is_unref)
static gpointer _g_module_symbol (gpointer handle, const gchar *symbol_name)
static gchar_g_module_build_path (const gchar *directory, const gchar *module_name)


Define Documentation

 
#define dlerror  )     "unknown dl-error"
 

Definition at line 43 of file gmodule-dl.c.

Referenced by fetch_dlerror().

#define RTLD_GLOBAL   0
 

Definition at line 72 of file gmodule-dl.c.

Referenced by _g_module_open(), and _g_module_self().

#define RTLD_LAZY   1
 

Definition at line 62 of file gmodule-dl.c.

Referenced by _g_module_open(), and _g_module_self().

#define RTLD_NOW   0
 

Definition at line 65 of file gmodule-dl.c.

Referenced by _g_module_open().


Function Documentation

static gchar* _g_module_build_path const gchar directory,
const gchar module_name
[static]
 

Definition at line 146 of file gmodule-dl.c.

References g_strconcat(), g_strdup(), and NULL.

Referenced by g_module_build_path().

00148 {
00149   if (directory && *directory) {
00150     if (strncmp (module_name, "lib", 3) == 0)
00151       return g_strconcat (directory, "/", module_name, NULL);
00152     else
00153       return g_strconcat (directory, "/lib", module_name, ".so", NULL);
00154   } else if (strncmp (module_name, "lib", 3) == 0)
00155     return g_strdup (module_name);
00156   else
00157     return g_strconcat ("lib", module_name, ".so", NULL);
00158 }

static void _g_module_close gpointer  handle,
gboolean  is_unref
[static]
 

Definition at line 117 of file gmodule-dl.c.

References fetch_dlerror(), and g_module_set_error().

Referenced by g_module_close(), and g_module_open().

00119 {
00120   /* are there any systems out there that have dlopen()/dlclose()
00121    * without a reference count implementation?
00122    */
00123   is_unref |= 1;
00124   
00125   if (is_unref)
00126     {
00127       if (dlclose (handle) != 0)
00128         g_module_set_error (fetch_dlerror ());
00129     }
00130 }

static gpointer _g_module_open const gchar file_name,
gboolean  bind_lazy
[static]
 

Definition at line 88 of file gmodule-dl.c.

References fetch_dlerror(), g_module_set_error(), RTLD_GLOBAL, RTLD_LAZY, and RTLD_NOW.

Referenced by g_module_open().

00090 {
00091   gpointer handle;
00092   
00093   handle = dlopen (file_name, RTLD_GLOBAL | (bind_lazy ? RTLD_LAZY : RTLD_NOW));
00094   if (!handle)
00095     g_module_set_error (fetch_dlerror ());
00096   
00097   return handle;
00098 }

static gpointer _g_module_self void   )  [static]
 

Definition at line 101 of file gmodule-dl.c.

References fetch_dlerror(), g_module_set_error(), NULL, RTLD_GLOBAL, and RTLD_LAZY.

Referenced by g_module_open().

00102 {
00103   gpointer handle;
00104   
00105   /* to query symbols from the program itself, special link options
00106    * are required on some systems.
00107    */
00108   
00109   handle = dlopen (NULL, RTLD_GLOBAL | RTLD_LAZY);
00110   if (!handle)
00111     g_module_set_error (fetch_dlerror ());
00112   
00113   return handle;
00114 }

static gpointer _g_module_symbol gpointer  handle,
const gchar symbol_name
[static]
 

Definition at line 133 of file gmodule-dl.c.

References fetch_dlerror(), and g_module_set_error().

Referenced by g_module_symbol().

00135 {
00136   gpointer p;
00137   
00138   p = dlsym (handle, symbol_name);
00139   if (!p)
00140     g_module_set_error (fetch_dlerror ());
00141   
00142   return p;
00143 }

static gchar* fetch_dlerror void   )  [static]
 

Definition at line 78 of file gmodule-dl.c.

References dlerror.

Referenced by _g_module_close(), _g_module_open(), _g_module_self(), and _g_module_symbol().

00079 {
00080   gchar *msg = dlerror ();
00081 
00082   /* make sure we always return an error message != NULL */
00083 
00084   return msg ? msg : "unknown dl-error";
00085 }


© sourcejam.com 2005-2008