diff --git a/core/systems/LibrarySys.cpp b/core/systems/LibrarySys.cpp index 641cc22f..02bc7fed 100644 --- a/core/systems/LibrarySys.cpp +++ b/core/systems/LibrarySys.cpp @@ -286,11 +286,23 @@ void LibrarySystem::GetPlatformError(char *error, size_t maxlength) maxlength, NULL); #elif defined PLATFORM_POSIX - snprintf(error, maxlength, "%s", strerror(errno)); + UTIL_Format(error, maxlength, "%s", strerror(errno)); #endif } } +void LibrarySystem::GetLoaderError(char *buffer, size_t maxlength) +{ +#if defined PLATFORM_WINDOWS + GetPlatformError(buffer, maxlength); +#elif defined PLATFORM_POSIX + if (buffer != NULL && maxlength) + { + strncopy(buffer, dlerror(), maxlength); + } +#endif +} + void LibrarySystem::CloseDirectory(IDirectory *dir) { delete dir; @@ -301,20 +313,16 @@ ILibrary *LibrarySystem::OpenLibrary(const char *path, char *error, size_t maxle LibraryHandle lib; #if defined PLATFORM_WINDOWS lib = LoadLibraryA(path); - if (!lib) - { - GetPlatformError(error, maxlength); - return false; - } #elif defined PLATFORM_POSIX lib = dlopen(path, RTLD_NOW); - if (!lib) - { - GetPlatformError(error, maxlength); - return false; - } #endif + if (lib == NULL) + { + GetLoaderError(error, maxlength); + return NULL; + } + return new CLibrary(lib); } diff --git a/core/systems/LibrarySys.h b/core/systems/LibrarySys.h index 0a948b83..45a94921 100644 --- a/core/systems/LibrarySys.h +++ b/core/systems/LibrarySys.h @@ -95,6 +95,7 @@ public: bool CreateFolder(const char *path); size_t GetFileFromPath(char *buffer, size_t maxlength, const char *path); bool FileTime(const char *path, FileTimeType type, time_t *pTime); + void GetLoaderError(char *buffer, size_t maxlength); }; extern LibrarySystem g_LibSys;