X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=lib%2FSupport%2FWindows%2FPath.inc;h=839beebfcb6494c3dc3802f24d91a54c431df94f;hp=2c111321c60ce89859cb8b6451376a7b3cd73ab6;hb=2f01bc86e5c3d33d16e35a45a5b0da9f05415adb;hpb=0f31d547ebc0f302085ff0046cdfae99710b0f76 diff --git a/lib/Support/Windows/Path.inc b/lib/Support/Windows/Path.inc index 2c111321c60..839beebfcb6 100644 --- a/lib/Support/Windows/Path.inc +++ b/lib/Support/Windows/Path.inc @@ -753,16 +753,20 @@ std::error_code openFileForWrite(const Twine &Name, int &ResultFD, namespace path { -bool home_directory(SmallVectorImpl &result) { - wchar_t Path[MAX_PATH]; - if (::SHGetFolderPathW(0, CSIDL_APPDATA | CSIDL_FLAG_CREATE, 0, - /*SHGFP_TYPE_CURRENT*/0, Path) != S_OK) +namespace { +bool getKnownFolderPath(KNOWNFOLDERID folderId, SmallVectorImpl &result) { + wchar_t *path = nullptr; + if (::SHGetKnownFolderPath(folderId, KF_FLAG_CREATE, nullptr, &path) != S_OK) return false; - if (UTF16ToUTF8(Path, ::wcslen(Path), result)) - return false; + bool ok = !UTF16ToUTF8(path, ::wcslen(path), result); + ::CoTaskMemFree(path); + return ok; +} +} - return true; +bool home_directory(SmallVectorImpl &result) { + return getKnownFolderPath(FOLDERID_Profile, result); } static bool getTempDirEnvVar(const char *Var, SmallVectorImpl &Res) {