[PATCH] D13753: Use Windows Vista API to get the user's home directory
Paweł Bylica via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 14 15:58:41 PDT 2015
chfast created this revision.
chfast added a subscriber: llvm-commits.
chfast set the repository for this revision to rL LLVM.
This patch raises Windows API requirement to Vista (`_WIN32_WINNT = 0x0600`) and replaces usage of deprecated SHGetFolderPathW with SHGetKnownFolderPath. The usage of SHGetKnownFolderPath is wrapped to allow queries for other "known" folders in the near future.
Repository:
rL LLVM
http://reviews.llvm.org/D13753
Files:
lib/Support/Windows/Path.inc
lib/Support/Windows/WindowsSupport.h
unittests/Support/Path.cpp
Index: unittests/Support/Path.cpp
===================================================================
--- unittests/Support/Path.cpp
+++ unittests/Support/Path.cpp
@@ -299,16 +299,21 @@
}
TEST(Support, HomeDirectory) {
-#ifdef LLVM_ON_UNIX
- // This test only makes sense on Unix if $HOME is set.
- if (::getenv("HOME")) {
+#ifdef LLVM_ON_WIN32
+ auto var = "HOME";
+#else
+ auto var = "USERPROFILE";
#endif
- SmallString<128> HomeDir;
- EXPECT_TRUE(path::home_directory(HomeDir));
+ SmallString<128> HomeDir;
+ auto status = path::home_directory(HomeDir);
+ if (auto expected = ::getenv(var)) {
+ EXPECT_TRUE(status);
EXPECT_FALSE(HomeDir.empty());
-#ifdef LLVM_ON_UNIX
+ EXPECT_EQ(expected, HomeDir);
+ } else {
+ EXPECT_FALSE(status);
+ EXPECT_TRUE(HomeDir.empty());
}
-#endif
}
class FileSystemTest : public testing::Test {
Index: lib/Support/Windows/WindowsSupport.h
===================================================================
--- lib/Support/Windows/WindowsSupport.h
+++ lib/Support/Windows/WindowsSupport.h
@@ -26,8 +26,8 @@
#undef _WIN32_WINNT
#undef _WIN32_IE
-// Require at least Windows XP(5.1) API.
-#define _WIN32_WINNT 0x0501
+// Require at least Windows Vista API.
+#define _WIN32_WINNT 0x0600
#define _WIN32_IE 0x0600 // MinGW at it again.
#define WIN32_LEAN_AND_MEAN
Index: lib/Support/Windows/Path.inc
===================================================================
--- lib/Support/Windows/Path.inc
+++ lib/Support/Windows/Path.inc
@@ -753,16 +753,20 @@
namespace path {
-bool home_directory(SmallVectorImpl<char> &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<char> &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<char> &result) {
+ return getKnownFolderPath(FOLDERID_Profile, result);
}
static bool getTempDirEnvVar(const char *Var, SmallVectorImpl<char> &Res) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13753.37412.patch
Type: text/x-patch
Size: 2381 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151014/1ea38cd4/attachment.bin>
More information about the llvm-commits
mailing list