Match GetPayloadPath code in nearby/internal/platform/implementation/windows/platform.cc

PiperOrigin-RevId: 427062438
This commit is contained in:
hai007
2022-02-07 17:31:31 -08:00
committed by Copybara-Service
parent 37f8b4487e
commit 3c9565a923
@@ -519,11 +519,15 @@ std::string GetPayloadPath(location::nearby::PayloadId payload_id) {
// process is responsible for freeing this resource once it
// is no longer needed by calling CoTaskMemFree, whether
// SHGetKnownFolderPath succeeds or not.
char *fullpathUTF8 = new char((wcslen(basePath) + 1) * sizeof(char));
wcstombs(fullpathUTF8, basePath, (wcslen(basePath) + 1) * sizeof(char));
return absl::StrCat(fullpathUTF8, "\\", payload_id);
size_t bufferSize;
wcstombs_s(&bufferSize, NULL, 0, basePath, 0);
char *fullpathUTF8 = new char[bufferSize + 1];
memset(fullpathUTF8, 0, bufferSize);
wcstombs_s(&bufferSize, fullpathUTF8, bufferSize, basePath, bufferSize - 1);
std::string fullPath = std::string(fullpathUTF8);
auto retval = absl::StrCat(fullPath, "\\", payload_id);
delete[] fullpathUTF8;
return retval;
}
void SendPayloadDart(Core *pCore, const char *endpoint_id,