mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 06:43:45 +01:00
Merge #14192: utils: Convert fs::filesystem_error messages from local multibyte to utf-8 on Windows
e221368932 utils: Convert fs error messages from multibyte to utf-8 (Chun Kuan Lee)
Pull request description:
Before:

After:

Tree-SHA512: 0a598bd159286f6784d117b8a24888b2650d5402d687ab0e8d0849e0c3d53797e266647d8177bb6614307c9598019cd7477311bb9895b1bb52a6bd77b460fda1
This commit is contained in:
16
src/fs.cpp
16
src/fs.cpp
@@ -97,4 +97,20 @@ bool FileLock::TryLock()
|
||||
}
|
||||
#endif
|
||||
|
||||
std::string get_filesystem_error_message(const fs::filesystem_error& e)
|
||||
{
|
||||
#ifndef WIN32
|
||||
return e.what();
|
||||
#else
|
||||
// Convert from Multi Byte to utf-16
|
||||
std::string mb_string(e.what());
|
||||
int size = MultiByteToWideChar(CP_ACP, 0, mb_string.c_str(), mb_string.size(), nullptr, 0);
|
||||
|
||||
std::wstring utf16_string(size, L'\0');
|
||||
MultiByteToWideChar(CP_ACP, 0, mb_string.c_str(), mb_string.size(), &*utf16_string.begin(), size);
|
||||
// Convert from utf-16 to utf-8
|
||||
return std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t>().to_bytes(utf16_string);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // fsbridge
|
||||
|
||||
Reference in New Issue
Block a user