summaryrefslogtreecommitdiffstats
path: root/eglib
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2008-02-01 11:32:10 +0000
committerJohan Hedberg <johan.hedberg@nokia.com>2008-02-01 11:32:10 +0000
commita797f53418e4f58b570c4a355dd46b33f2f68906 (patch)
tree2dedf091226b56b946fcc6bd3e95adf533931de5 /eglib
parent08fa71cc327de929ebe0c36b3d2eb0fa5190e441 (diff)
Add GModule support to eglib
Diffstat (limited to 'eglib')
-rw-r--r--eglib/gmain.c69
-rw-r--r--eglib/gmain.h16
2 files changed, 85 insertions, 0 deletions
diff --git a/eglib/gmain.c b/eglib/gmain.c
index b341d516..ce35b816 100644
--- a/eglib/gmain.c
+++ b/eglib/gmain.c
@@ -16,6 +16,7 @@
#include <sys/mman.h>
#include <sys/file.h>
#include <ctype.h>
+#include <dlfcn.h>
#include <gmain.h>
@@ -1577,3 +1578,71 @@ gchar *g_string_free(GString *string, gboolean free_segment)
return segment;
}
+
+/* GModule */
+
+struct _GModule {
+ void *handle;
+};
+
+static const char *dl_error_string = NULL;
+
+GModule *g_module_open(const gchar *file_name, GModuleFlags flags)
+{
+ GModule *module;
+
+ module = g_try_new0(GModule, 1);
+ if (module == NULL) {
+ dl_error_string = strerror(ENOMEM);
+ return NULL;
+ }
+
+ module->handle = dlopen(file_name, flags);
+
+ if (module->handle == NULL) {
+ dl_error_string = dlerror();
+ g_free(module);
+ return NULL;
+ }
+
+ return module;
+}
+
+gboolean g_module_symbol(GModule *module, const gchar *symbol_name,
+ gpointer *symbol)
+{
+ void *sym;
+
+ dlerror();
+ sym = dlsym(module->handle, symbol_name);
+ dl_error_string = dlerror();
+
+ if (dl_error_string != NULL)
+ return FALSE;
+
+ *symbol = sym;
+
+ return TRUE;
+}
+
+gboolean g_module_close(GModule *module)
+{
+ if (dlclose(module->handle) != 0) {
+ dl_error_string = dlerror();
+ return FALSE;
+ }
+
+ g_free(module);
+
+ return TRUE;
+}
+
+const gchar *g_module_error(void)
+{
+ const char *str;
+
+ str = dl_error_string;
+ dl_error_string = NULL;
+
+ return str;
+}
diff --git a/eglib/gmain.h b/eglib/gmain.h
index 2ed00fb3..cfc53378 100644
--- a/eglib/gmain.h
+++ b/eglib/gmain.h
@@ -279,4 +279,20 @@ void g_string_append_printf(GString *string, const gchar *format, ...);
gchar *g_string_free(GString *string, gboolean free_segment);
+/* GModule */
+
+typedef struct _GModule GModule;
+
+typedef enum {
+ G_MODULE_BIND_LAZY = 1 << 0,
+ G_MODULE_BIND_LOCAL = 1 << 1,
+ G_MODULE_BIND_MASK = 0x03
+} GModuleFlags;
+
+GModule *g_module_open(const gchar *file_name, GModuleFlags flags);
+gboolean g_module_symbol(GModule *module, const gchar *symbol_name,
+ gpointer *symbol);
+gboolean g_module_close(GModule *module);
+const gchar *g_module_error(void);
+
#endif /* __GMAIN_H */