System/Path/Windows: Generalize GetUserHomeDirectory.
authorMichael J. Spencer <bigcheesegs@gmail.com>
Tue, 9 Nov 2010 15:11:31 +0000 (15:11 +0000)
committerMichael J. Spencer <bigcheesegs@gmail.com>
Tue, 9 Nov 2010 15:11:31 +0000 (15:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118506 91177308-0d34-0410-b5e6-96231b3b80d8

lib/System/Win32/Path.inc

index 9187c8279381bb0df82b716c3a4098051f3a8ec4..b0cca0e33624e5ee3b114f92ab528a920ea771c4 100644 (file)
@@ -293,14 +293,15 @@ Path::GetLLVMDefaultConfigDir() {
 
 Path
 Path::GetUserHomeDirectory() {
-  // TODO: Typical Windows setup doesn't define HOME.
-  const char* home = getenv("HOME");
-  if (home) {
-    Path result;
-    if (result.set(home))
-      return result;
-  }
-  return GetRootDirectory();
+  char buff[MAX_PATH];
+  HRESULT res =  SHGetFolderPathA(NULL,
+                                  CSIDL_FLAG_CREATE | CSIDL_APPDATA,
+                                  NULL,
+                                  SHGFP_TYPE_CURRENT,
+                                  buff);
+  if (res != S_OK)
+    assert(0 && "Failed to get user home directory");
+  return Path(buff);
 }
 
 Path