aboutsummaryrefslogtreecommitdiff
path: root/src/dynamic.cpp
diff options
context:
space:
mode:
authorGravatar Sadie Powell2022-12-25 22:28:12 +0000
committerGravatar Sadie Powell2022-12-25 22:44:50 +0000
commit05168e354992d688d24a902787f4c51433ad7ef3 (patch)
treed82629266081635e8f62e48e966ec8ebd73de2d8 /src/dynamic.cpp
parentRefactor SocketEngine slightly. (diff)
parentUpdate the Windows dependencies. (diff)
Merge branch 'insp3' into master.
Diffstat (limited to 'src/dynamic.cpp')
-rw-r--r--src/dynamic.cpp13
1 files changed, 4 insertions, 9 deletions
diff --git a/src/dynamic.cpp b/src/dynamic.cpp
index 6f1e5dce6..20db9bac8 100644
--- a/src/dynamic.cpp
+++ b/src/dynamic.cpp
@@ -115,19 +115,14 @@ void* DLLManager::GetSymbol(const char* name) const
void DLLManager::RetrieveLastError()
{
-#if defined _WIN32
- char errmsg[500];
- DWORD dwErrorCode = GetLastError();
- if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, dwErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)errmsg, _countof(errmsg), nullptr) == 0)
- sprintf_s(errmsg, _countof(errmsg), "Error code: %u", dwErrorCode);
+#ifdef _WIN32
+ err = GetErrorMessage(GetLastError());
SetLastError(ERROR_SUCCESS);
- err = errmsg;
#else
const char* errmsg = dlerror();
err = errmsg ? errmsg : "Unknown error";
#endif
- std::string::size_type p;
- while ((p = err.find_last_of("\r\n")) != std::string::npos)
- err.erase(p, 1);
+ for (size_t pos = 0; ((pos = err.find_first_of("\r\n", pos)) != std::string::npos); )
+ err[pos] = ' ';
}