From 9225eadeb28150fcb0b05ec0b31349ce812dd3d0 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Fri, 1 Feb 2008 14:21:14 +0000 Subject: Move GModule code to gmodule.c and gmodule.h --- eglib/gmodule.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 eglib/gmodule.c (limited to 'eglib/gmodule.c') diff --git a/eglib/gmodule.c b/eglib/gmodule.c new file mode 100644 index 00000000..d9ece8d7 --- /dev/null +++ b/eglib/gmodule.c @@ -0,0 +1,76 @@ +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +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; +} -- cgit From 0ef72a5769f1c283786aa105d67127d6b113168c Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Tue, 11 Mar 2008 22:54:59 +0000 Subject: Add g_dir* and g_str_has_prefix functions to eglib. --- eglib/gmodule.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'eglib/gmodule.c') diff --git a/eglib/gmodule.c b/eglib/gmodule.c index d9ece8d7..c3400823 100644 --- a/eglib/gmodule.c +++ b/eglib/gmodule.c @@ -11,6 +11,7 @@ struct _GModule { void *handle; + gchar *file_name; }; static const char *dl_error_string = NULL; @@ -33,6 +34,8 @@ GModule *g_module_open(const gchar *file_name, GModuleFlags flags) return NULL; } + module->file_name = g_strdup(file_name); + return module; } @@ -74,3 +77,11 @@ const gchar *g_module_error(void) return str; } + +const gchar *g_module_name(GModule *module) +{ + if (module == NULL) + return NULL; + + return module->file_name; +} -- cgit From e6bce39040a253c0bf62e26ab275e3cf307ed288 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 11 Mar 2008 23:45:09 +0000 Subject: Fix memory leaks and coding style in eglib --- eglib/gmodule.c | 1 + 1 file changed, 1 insertion(+) (limited to 'eglib/gmodule.c') diff --git a/eglib/gmodule.c b/eglib/gmodule.c index c3400823..7224a9f6 100644 --- a/eglib/gmodule.c +++ b/eglib/gmodule.c @@ -63,6 +63,7 @@ gboolean g_module_close(GModule *module) return FALSE; } + g_free(module->file_name); g_free(module); return TRUE; -- cgit