mirror of
https://github.com/google/benchmark.git
synced 2025-03-13 18:50:11 +08:00
Fixes incorrect wide string conversion on win32 (#1516)
* fixes incorrect wide string conversion on win32 * removed redundant error checks
This commit is contained in:
parent
2257fa4d6a
commit
e67028c510
@ -423,19 +423,12 @@ std::string GetSystemName() {
|
||||
#ifndef UNICODE
|
||||
str = std::string(hostname, DWCOUNT);
|
||||
#else
|
||||
std::vector<wchar_t> converted;
|
||||
// Find the length first.
|
||||
int len = ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, hostname,
|
||||
DWCOUNT, converted.begin(), 0);
|
||||
// TODO: Report error from GetLastError()?
|
||||
if (len == 0) return std::string("");
|
||||
converted.reserve(len + 1);
|
||||
|
||||
len = ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, hostname, DWCOUNT,
|
||||
converted.begin(), converted.size());
|
||||
// TODO: Report error from GetLastError()?
|
||||
if (len == 0) return std::string("");
|
||||
str = std::string(converted.data());
|
||||
// `WideCharToMultiByte` returns `0` when conversion fails.
|
||||
int len = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, hostname,
|
||||
DWCOUNT, NULL, 0, NULL, NULL);
|
||||
str.resize(len);
|
||||
WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, hostname, DWCOUNT, &str[0],
|
||||
str.size(), NULL, NULL);
|
||||
#endif
|
||||
return str;
|
||||
#elif defined(BENCHMARK_OS_QURT)
|
||||
|
Loading…
Reference in New Issue
Block a user