diff options
author | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:28:01 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:28:01 +0200 |
commit | fe9eb89ebc1b3c33cbac00a3fa095a14faef9113 (patch) | |
tree | 8a3bb620a9acb83fe0057061a86e8f2cb91a9fe1 /zen/sys_error.h | |
parent | 5.21 (diff) | |
download | FreeFileSync-fe9eb89ebc1b3c33cbac00a3fa095a14faef9113.tar.gz FreeFileSync-fe9eb89ebc1b3c33cbac00a3fa095a14faef9113.tar.bz2 FreeFileSync-fe9eb89ebc1b3c33cbac00a3fa095a14faef9113.zip |
5.22
Diffstat (limited to 'zen/sys_error.h')
-rw-r--r-- | zen/sys_error.h | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/zen/sys_error.h b/zen/sys_error.h index cea2f5f9..dc60c77f 100644 --- a/zen/sys_error.h +++ b/zen/sys_error.h @@ -73,13 +73,17 @@ std::wstring formatSystemError(const std::wstring& functionName, long long lastE inline std::wstring formatSystemError(const std::wstring& functionName, ErrorCode lastError) { - //determine error code if none was specified -> still required?? + const ErrorCode currentError = getLastError(); //not necessarily == lastError + + //determine error code if none was specified if (lastError == 0) - lastError = getLastError(); + lastError = currentError; std::wstring output = replaceCpy(_("Error Code %x:"), L"%x", numberTo<std::wstring>(lastError)); #ifdef ZEN_WIN + ZEN_ON_SCOPE_EXIT(::SetLastError(currentError)); //this function must not change active system error variable! + LPWSTR buffer = nullptr; if (::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_MAX_WIDTH_MASK | @@ -91,13 +95,12 @@ std::wstring formatSystemError(const std::wstring& functionName, ErrorCode lastE output += L" "; output += buffer; } - ::SetLastError(lastError); //restore last error #elif defined ZEN_LINUX || defined ZEN_MAC + ZEN_ON_SCOPE_EXIT(errno = currentError); + output += L" "; output += utfCvrtTo<std::wstring>(::strerror(lastError)); - - errno = lastError; //restore errno #endif if (!endsWith(output, L" ")) //Windows messages seem to end with a blank... output += L" "; |