summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2013-02-20 10:08:34 +0100
committerStef Walter <stefw@gnome.org>2013-03-03 10:06:45 +0100
commitb06bee023df6f4f2b004030e86e8ee90579681f5 (patch)
treee17f54b098b9e82cca3b8ae76ce5470f18b4cccc /common
parent6521cccc021530f59f2f5e60a9cbf0c5b458360d (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
Diffstat (limited to 'common')
-rw-r--r--common/compat.c18
-rw-r--r--common/compat.h20
2 files changed, 19 insertions, 19 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 }; \