diff options
author | Stef Walter <stefw@gnome.org> | 2013-02-20 10:08:34 +0100 |
---|---|---|
committer | Stef Walter <stefw@gnome.org> | 2013-03-03 10:06:45 +0100 |
commit | b06bee023df6f4f2b004030e86e8ee90579681f5 (patch) | |
tree | e17f54b098b9e82cca3b8ae76ce5470f18b4cccc | |
parent | 6521cccc021530f59f2f5e60a9cbf0c5b458360d (diff) |
Rename p11_module_xxx() compat functions to p11_dl_xxx()
For clarity. In addition, make p11_dl_close() able to be used
as a destroyer callback.
Also make p11_dl_error() return an allocated string
-rw-r--r-- | common/compat.c | 18 | ||||
-rw-r--r-- | common/compat.h | 20 | ||||
-rw-r--r-- | p11-kit/modules.c | 15 |
3 files changed, 29 insertions, 24 deletions
diff --git a/common/compat.c b/common/compat.c index b917cfa..59aaa00 100644 --- a/common/compat.c +++ b/common/compat.c @@ -127,19 +127,23 @@ p11_mutex_init (p11_mutex_t *mutex) pthread_mutexattr_destroy (&attr); } +char * +p11_dl_error (void) +{ + const char *msg = dlerror (); + return msg ? strdup (msg) : NULL; +} + #endif /* OS_UNIX */ #ifdef OS_WIN32 -const char * -p11_module_error (void) +char * +p11_dl_error (void) { DWORD code = GetLastError(); - p11_local *local; LPVOID msg_buf; - local = p11_library_get_thread_local (); - FormatMessageA (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, @@ -147,10 +151,6 @@ p11_module_error (void) MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&msg_buf, 0, NULL); - if (local->last_error) - LocalFree (local->last_error); - local->last_error = msg_buf; - return msg_buf; } diff --git a/common/compat.h b/common/compat.h index 5bcdfe2..48d97b3 100644 --- a/common/compat.h +++ b/common/compat.h @@ -115,14 +115,14 @@ int p11_thread_join (thread_t thread); typedef HMODULE dl_module_t; -#define p11_module_open(f) \ +#define p11_dl_open(f) \ (LoadLibrary (f)) -#define p11_module_close(d) \ +#define p11_dl_close(d) \ (FreeLibrary (d)) -#define p11_module_symbol(d, s) \ +#define p11_dl_symbol(d, s) \ ((void *)GetProcAddress ((d), (s))) -const char * p11_module_error (void); +char * p11_dl_error (void); #define p11_sleep_ms(ms) \ (Sleep (ms)) @@ -165,15 +165,15 @@ typedef void * (*p11_thread_routine) (void *arg); typedef void * dl_module_t; -#define p11_module_open(f) \ +#define p11_dl_open(f) \ (dlopen ((f), RTLD_LOCAL | RTLD_NOW)) -#define p11_module_close(d) \ - (dlclose(d)) -#define p11_module_error() \ - (dlerror ()) -#define p11_module_symbol(d, s) \ +#define p11_dl_close \ + dlclose +#define p11_dl_symbol(d, s) \ (dlsym ((d), (s))) +char * p11_dl_error (void); + #define p11_sleep_ms(ms) \ do { int _ms = (ms); \ struct timespec _ts = { _ms / 1000, (_ms % 1000) * 1000 * 1000 }; \ diff --git a/p11-kit/modules.c b/p11-kit/modules.c index 62ecbe7..eaa1564 100644 --- a/p11-kit/modules.c +++ b/p11-kit/modules.c @@ -190,7 +190,7 @@ free_module_unlocked (void *data) assert (mod->ref_count == 0); if (mod->dl_module) - p11_module_close (mod->dl_module); + p11_dl_close (mod->dl_module); p11_mutex_uninit (&mod->initialize_mutex); p11_dict_free (mod->config); @@ -253,21 +253,26 @@ static CK_RV dlopen_and_get_function_list (Module *mod, const char *path) { CK_C_GetFunctionList gfl; + char *error; CK_RV rv; assert (mod); assert (path); - mod->dl_module = p11_module_open (path); + mod->dl_module = p11_dl_open (path); if (mod->dl_module == NULL) { - p11_message ("couldn't load module: %s: %s", path, p11_module_error ()); + error = p11_dl_error (); + p11_message ("couldn't load module: %s: %s", path, error); + free (error); return CKR_GENERAL_ERROR; } - gfl = p11_module_symbol (mod->dl_module, "C_GetFunctionList"); + gfl = p11_dl_symbol (mod->dl_module, "C_GetFunctionList"); if (!gfl) { + error = p11_dl_error (); p11_message ("couldn't find C_GetFunctionList entry point in module: %s: %s", - path, p11_module_error ()); + path, error); + free (error); return CKR_GENERAL_ERROR; } |