Skip to content

Commit 37b836a

Browse files
committed
Merge #13888: Call unicode API on Windows
d38bf91 Call unicode API on Windows (Chun Kuan Lee) Pull request description: Call Unicode API on Windows Tree-SHA512: 93c290ee79c9d911fdada8ba45e184fc4f14d3cb56f33f39223286213878b08e8c4dd296a80099c57797d3b8589870e6cff622b22e76123d7452659d49dd8309
2 parents 477f258 + d38bf91 commit 37b836a

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/netbase.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#ifndef WIN32
1919
#include <fcntl.h>
20+
#else
21+
#include <codecvt>
2022
#endif
2123

2224
#if !defined(MSG_NOSIGNAL)
@@ -649,13 +651,13 @@ bool LookupSubNet(const char* pszName, CSubNet& ret)
649651
#ifdef WIN32
650652
std::string NetworkErrorString(int err)
651653
{
652-
char buf[256];
654+
wchar_t buf[256];
653655
buf[0] = 0;
654-
if(FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
656+
if(FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
655657
nullptr, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
656-
buf, sizeof(buf), nullptr))
658+
buf, ARRAYSIZE(buf), nullptr))
657659
{
658-
return strprintf("%s (%d)", buf, err);
660+
return strprintf("%s (%d)", std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,wchar_t>().to_bytes(buf), err);
659661
}
660662
else
661663
{

src/util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ void CreatePidFile(const fs::path &path, pid_t pid)
998998
bool RenameOver(fs::path src, fs::path dest)
999999
{
10001000
#ifdef WIN32
1001-
return MoveFileExA(src.string().c_str(), dest.string().c_str(),
1001+
return MoveFileExW(src.wstring().c_str(), dest.wstring().c_str(),
10021002
MOVEFILE_REPLACE_EXISTING) != 0;
10031003
#else
10041004
int rc = std::rename(src.string().c_str(), dest.string().c_str());

0 commit comments

Comments
 (0)