diff options
-rw-r--r-- | include/wolf/library/loader.h | 34 | ||||
-rw-r--r-- | src/library/loader.c | 21 |
2 files changed, 34 insertions, 21 deletions
diff --git a/include/wolf/library/loader.h b/include/wolf/library/loader.h index 85195a7..949d946 100644 --- a/include/wolf/library/loader.h +++ b/include/wolf/library/loader.h @@ -36,6 +36,7 @@ extern "C" { #include "port/sys.h" #include "errors.h" +#include <sys/types.h> /* for size_t */ /* @brief handle representing a shared library */ @@ -53,34 +54,25 @@ wolf_library_p wolf_library_load( const char *name, wolf_error_t *error ); /** * Free up resources used by the library object. * - * @param demon the library object to free + * @param library the library object to free * * @return WOLF_OK if library has been unloaded, * WOLF_ERR_INTERNAL_STATE if the library handle is in an illegal state * (like double freeing the same library) */ - wolf_error_t wolf_library_unload( wolf_library_p library ); -#if 0 - -#if !defined _WIN32 - -#include <dlfcn.h> /* for dlxxx functions */ - - -#else - -#define WIN32_MEAN_AND_LEAN -#include <windows.h> - -#endif /* !defined _WIN32 */ - -#endif - -#ifdef __cplusplus -} -#endif +/** + * Converts the last error and state of the library object in a human readable message. + * + * @param error the error which happened after calling a library loader function + * @param library the library object for which we want a error message + * @param buf the buffer which will hold the error message + * @param buflen the size of the buffer + * + * @returns a pointer to buf for convenience + */ +char *wolf_libary_errmsg( const wolf_error_t error, const wolf_library_p library, char *buf, size_t buflen ); /** @} */ /* @addtogroup wolf_library */ diff --git a/src/library/loader.c b/src/library/loader.c index 1f8ce20..173607c 100644 --- a/src/library/loader.c +++ b/src/library/loader.c @@ -20,6 +20,8 @@ #include "port/unused.h" #include "port/stdlib.h" /* for malloc, free */ +#include "port/stdio.h" /* for snprintf */ +#include "port/gettext.h" /* for i18n */ #ifdef HAVE_DLFCN #include <dlfcn.h> /* for dlopen. dlclose functions */ @@ -75,3 +77,22 @@ 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 ) { + 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; + } + + return buf; +} |