From b13ddadad16b2b39ad00cef1ceb19c865335c0ae Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Mon, 24 May 2010 20:53:46 +0200 Subject: better error handling in library loader --- tests/library/test_loader.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/library/test_loader.c b/tests/library/test_loader.c index bda32b3..75f968b 100644 --- a/tests/library/test_loader.c +++ b/tests/library/test_loader.c @@ -26,6 +26,7 @@ #else #define LIBRARY_NAME "./testlib.so.0.0.0" #endif +#define LIBRARY_FUNC "multiply_by_two2" int main( void ) { wolf_library_p library; @@ -39,16 +40,22 @@ int main( void ) { /* open the libray */ library = wolf_library_load( LIBRARY_NAME, &error ); if( error != WOLF_OK ) { - fprintf( stderr, "Error %d loading the library: %s\n", - error, wolf_library_errmsg( error, library, errbuf, 512 ) ); + fprintf( stderr, "Error %d (%s) loading library '%s':\n", + error, wolf_error_msg( error, errbuf, 512 ), LIBRARY_NAME ); + fprintf( stderr, "Internal loader error: %s\n", + wolf_library_error_msg( library, errbuf, 512 ) ); + (void)wolf_library_unload( library ); return EXIT_FAILURE; } /* fetch a known function symbol (multiply_by_two) */ - symbol = wolf_library_get_func( library, "multiply_by_two", &error ); + symbol = wolf_library_get_func( library, LIBRARY_FUNC, &error ); if( error != WOLF_OK ) { - fprintf( stderr, "Error %d fetching a function from the library: %s\n", - error, wolf_library_errmsg( error, library, errbuf, 512 ) ); + fprintf( stderr, "Error %d (%s) fetching function '%s' from the library\n", + error, wolf_error_msg( error, errbuf, 512 ), LIBRARY_FUNC ); + fprintf( stderr, "Internal loader error: %s\n", + wolf_library_error_msg( library, errbuf, 512 ) ); + (void)wolf_library_unload( library ); return EXIT_FAILURE; } WOLF_LIBRARY_FUNC_CAST( symbol, multiply_by_two_func, func ); @@ -60,8 +67,10 @@ int main( void ) { /* close library */ error = wolf_library_unload( library ); if( error != WOLF_OK ) { - fprintf( stderr, "Error %d unloading the library: %s\n", - error, wolf_library_errmsg( error, library, errbuf, 512 ) ); + fprintf( stderr, "Error %d (%s) unloading the library\n", + error, wolf_error_msg( error, errbuf, 512 ) ); + fprintf( stderr, "Internal loader error: %s\n", + wolf_library_error_msg( library, errbuf, 512 ) ); return EXIT_FAILURE; } -- cgit v1.2.3-54-g00ecf