From 08823730905d8dfefc8c8f1202dab5f28923968c Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 23 May 2010 12:39:27 +0200 Subject: better error handling in library loader --- src/errors.c | 1 + src/library/loader.c | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/errors.c b/src/errors.c index efd3f15..a453dbe 100644 --- a/src/errors.c +++ b/src/errors.c @@ -97,5 +97,6 @@ char *wolf_system_error_msg( char *buf, size_t buflen ) { return buf; #else (void)strerror_r( errno, buf, buflen ); + return buf; #endif } diff --git a/src/library/loader.c b/src/library/loader.c index 106df7f..93b9298 100644 --- a/src/library/loader.c +++ b/src/library/loader.c @@ -17,6 +17,8 @@ #include "library/loader.h" +#include "errors.h" + #include "port/sys_internal.h" #include "port/stdlib.h" /* for malloc, free */ @@ -61,7 +63,6 @@ wolf_library_p wolf_library_load( const char *name, wolf_error_t *error ) { * also make up our mind how many flags we should "leak" to the application layer */ flags = RTLD_NOW | RTLD_LOCAL; - l->handle = dlopen( name, flags ); if( l->handle == NULL ) { strncpy( l->errbuf, dlerror( ), INTERNAL_ERRBUF_SIZE ); @@ -72,7 +73,7 @@ wolf_library_p wolf_library_load( const char *name, wolf_error_t *error ) { #if defined _WIN32 l->handle = LoadLibrary( name ); if( l->handle == NULL ) { - strncpy( l->errbuf, "", INTERNAL_ERRBUF_SIZE ); + wolf_system_error_msg( l->errbuf, INTERNAL_ERRBUF_SIZE ); *error = WOLF_ERR_INTERNAL; return l; } @@ -106,7 +107,7 @@ wolf_error_t wolf_library_unload( wolf_library_p l ) { #if defined _WIN32 res = FreeLibrary( l->handle ); if( !res ) { - strncpy( l->errbuf, "", INTERNAL_ERRBUF_SIZE ); + wolf_system_error_msg( l->errbuf, INTERNAL_ERRBUF_SIZE ); return WOLF_ERR_INTERNAL; } #else @@ -144,7 +145,7 @@ WOLF_LIBRARY_FUNCPTR wolf_library_get_func( const wolf_library_p l, const char * #if defined _WIN32 ret = GetProcAddress( l->handle, name ); if( ret == NULL ) { - strncpy( l->errbuf, "", INTERNAL_ERRBUF_SIZE ); + wolf_system_error_msg( l->errbuf, INTERNAL_ERRBUF_SIZE ); *error = WOLF_ERR_INTERNAL; return ret; } -- cgit v1.2.3-54-g00ecf