diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2008-07-26 19:00:53 +0200 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2008-07-26 19:00:53 +0200 |
commit | d6ae1c3f777832f8e32702f81fe64e33a1396928 (patch) | |
tree | 159a1e59f3929c9d795dbd1f3edd84d9dccba048 /eglib/gmodule.c | |
parent | b8e5fea8d31fbcd3d1c044385f8217dbf39892bb (diff) | |
parent | 3382af9114a9b2e657c7ddd0a5511edda6a37a90 (diff) |
Import bluez-utils-3.36 revision history
Diffstat (limited to 'eglib/gmodule.c')
-rw-r--r-- | eglib/gmodule.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/eglib/gmodule.c b/eglib/gmodule.c new file mode 100644 index 00000000..7224a9f6 --- /dev/null +++ b/eglib/gmodule.c @@ -0,0 +1,88 @@ +#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; + gchar *file_name; +}; + +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; + } + + module->file_name = g_strdup(file_name); + + 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->file_name); + g_free(module); + + return TRUE; +} + +const gchar *g_module_error(void) +{ + const char *str; + + str = dl_error_string; + dl_error_string = NULL; + + return str; +} + +const gchar *g_module_name(GModule *module) +{ + if (module == NULL) + return NULL; + + return module->file_name; +} |