summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2010-05-18 17:03:31 +0200
committerAndreas Baumann <abaumann@yahoo.com>2010-05-18 17:03:31 +0200
commitb1a673c0a7ab8669e5c814979ab07b893efd9d50 (patch)
tree46b8122e855d492a7d98d4ed8650950827aca0c5 /src
parent150f99b09f9ecb5c837c5c184641c0b2aecf7a36 (diff)
downloadwolfbones-b1a673c0a7ab8669e5c814979ab07b893efd9d50.tar.gz
wolfbones-b1a673c0a7ab8669e5c814979ab07b893efd9d50.tar.bz2
first proper error handling for loader
Diffstat (limited to 'src')
-rw-r--r--src/library/loader.c33
1 files changed, 12 insertions, 21 deletions
diff --git a/src/library/loader.c b/src/library/loader.c
index 912afa4..3e58e0f 100644
--- a/src/library/loader.c
+++ b/src/library/loader.c
@@ -22,13 +22,18 @@
#include "port/stdlib.h" /* for malloc, free */
#include "port/stdio.h" /* for snprintf */
#include "port/gettext.h" /* for i18n */
+#include "port/string.h" /* for strncpy */
#ifdef HAVE_DLFCN
#include <dlfcn.h> /* for dlopen. dlclose functions */
#endif
+#define INTERNAL_ERRBUF_SIZE 256
+
struct wolf_library_t {
- void *handle; /**< the OS handle for the library */
+ void *handle; /**< the OS handle for the library */
+ char errbuf[INTERNAL_ERRBUF_SIZE]; /**< internal buffer to hold the error message
+ * we get with dlerror */
};
wolf_library_p wolf_library_load( const char *name, wolf_error_t *error ) {
@@ -49,8 +54,9 @@ wolf_library_p wolf_library_load( const char *name, wolf_error_t *error ) {
l->handle = dlopen( name, flags );
if( l->handle == NULL ) {
+ strncpy( l->errbuf, dlerror( ), INTERNAL_ERRBUF_SIZE );
*error = WOLF_ERR_INTERNAL;
- return NULL;
+ return l;
}
#else
#error Not using DLFCN as shared loader. Port first!
@@ -69,7 +75,7 @@ wolf_error_t wolf_library_unload( wolf_library_p l ) {
res = dlclose( l->handle );
if( res != 0 ) {
- return WOLF_ERR_INVALID_STATE;
+ return WOLF_ERR_INTERNAL;
}
free( l );
@@ -78,26 +84,11 @@ wolf_error_t wolf_library_unload( wolf_library_p l ) {
return WOLF_OK;
}
-char *wolf_libary_errmsg( const wolf_error_t error, const wolf_library_p library, char *buf, size_t buflen ) {
- WOLF_UNUSED( library );
+char *wolf_libary_errmsg( const wolf_error_t error, const wolf_library_p l, char *buf, size_t buflen ) {
(void)wolf_error_msg( error, buf, buflen );
-
-#if 0
- switch( error ) {
- /* TODO: we repeat ourself here! Have a function in errors.h for generic mapping? */
- case WOLF_ERR_OUT_OF_MEMORY:
- snprintf( buf, buflen, _( "Out of memory" ) );
- break;
-
- case WOLF_ERR_INVALID_STATE:
- snprintf( buf, buflen, _( "Invalid state" ) );
- break;
-
- default:
- snprintf( buf, buflen, _( "<unknown error>" ) );
- break;
+ if( error == WOLF_ERR_INTERNAL ) {
+ strncpy( buf + strlen( buf ), l->errbuf, buflen - strlen( buf ) );
}
-#endif
return buf;
}