Skip to content

Commit

Permalink
[Utils] Call unicode API on Windows
Browse files Browse the repository at this point in the history
Backports bitcoin#13888
  • Loading branch information
Warrows committed Oct 14, 2019
1 parent 6ad0a19 commit a7f5f32
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/netbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <arpa/inet.h>
#endif
#include <fcntl.h>
#else
#include <codecvt>
#endif

#include <boost/algorithm/string/case_conv.hpp> // for to_lower()
Expand Down Expand Up @@ -1400,12 +1402,12 @@ bool operator<(const CSubNet& a, const CSubNet& b)
#ifdef WIN32
std::string NetworkErrorString(int err)
{
char buf[256];
wchar_t buf[256];
buf[0] = 0;
if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
if (FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
buf, sizeof(buf), NULL)) {
return strprintf("%s (%d)", buf, err);
buf, ARRAYSIZE(buf), nullptr)) {
return strprintf("%s (%d)", std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,wchar_t>().to_bytes(buf), err);
} else {
return strprintf("Unknown error (%d)", err);
}
Expand Down
2 changes: 1 addition & 1 deletion src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ void CreatePidFile(const fs::path& path, pid_t pid)
bool RenameOver(fs::path src, fs::path dest)
{
#ifdef WIN32
return MoveFileExA(src.string().c_str(), dest.string().c_str(),
return MoveFileExW(src.wstring().c_str(), dest.wstring().c_str(),
MOVEFILE_REPLACE_EXISTING) != 0;
#else
int rc = std::rename(src.string().c_str(), dest.string().c_str());
Expand Down

0 comments on commit a7f5f32

Please sign in to comment.