diff options
-rw-r--r-- | eglib/Makefile.am | 2 | ||||
-rw-r--r-- | eglib/gmain.c | 68 | ||||
-rw-r--r-- | eglib/gmain.h | 16 | ||||
-rw-r--r-- | eglib/gmodule.c | 76 | ||||
-rw-r--r-- | eglib/gmodule.h | 20 |
5 files changed, 97 insertions, 85 deletions
diff --git a/eglib/Makefile.am b/eglib/Makefile.am index 009c70e1..e6166090 100644 --- a/eglib/Makefile.am +++ b/eglib/Makefile.am @@ -2,7 +2,7 @@ if !GLIB noinst_LTLIBRARIES = libeglib.la -libeglib_la_SOURCES = glib.h gmain.h gmain.c +libeglib_la_SOURCES = glib.h gmain.h gmain.c gmodule.h gmodule.c endif MAINTAINERCLEANFILES = Makefile.in diff --git a/eglib/gmain.c b/eglib/gmain.c index ce35b816..8b631eb5 100644 --- a/eglib/gmain.c +++ b/eglib/gmain.c @@ -1578,71 +1578,3 @@ 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 cfc53378..2ed00fb3 100644 --- a/eglib/gmain.h +++ b/eglib/gmain.h @@ -279,20 +279,4 @@ 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 */ 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 <stdio.h> +#include <errno.h> +#include <unistd.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <dlfcn.h> + +#include <gmain.h> +#include <gmodule.h> + +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/gmodule.h b/eglib/gmodule.h new file mode 100644 index 00000000..e1830595 --- /dev/null +++ b/eglib/gmodule.h @@ -0,0 +1,20 @@ +#ifndef __GMODULE_H +#define __GMODULE_H + +#include <gmain.h> + +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 /* __GMODULE_H */ |