From a55bbe356c33e67102110a0a511e39145a159946 Mon Sep 17 00:00:00 2001 From: Roman Zulak Date: Thu, 15 Sep 2016 21:19:46 -0400 Subject: [PATCH] Use llvm to get Home directory, was broken on Windows anyway. Signed-off-by: Vassil Vassilev --- lib/UserInterface/UserInterface.cpp | 39 ++--------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/lib/UserInterface/UserInterface.cpp b/lib/UserInterface/UserInterface.cpp index ed5968fe..7c7d2eb0 100644 --- a/lib/UserInterface/UserInterface.cpp +++ b/lib/UserInterface/UserInterface.cpp @@ -30,10 +30,6 @@ # include #endif -#if defined(LLVM_ON_WIN32) -#include -#endif - #if defined(_MSC_VER) #ifndef STDIN_FILENO # define STDIN_FILENO 0 @@ -48,36 +44,6 @@ #include -namespace { - -#if defined(LLVM_ON_UNIX) - static void GetUserHomeDirectory(llvm::SmallVectorImpl& str) { - str.clear(); - const char* home = getenv("HOME"); - if (!home) - home = "/"; - llvm::StringRef SRhome(home); - str.insert(str.begin(), SRhome.begin(), SRhome.end()); - } -#elif defined(LLVM_ON_WIN32) - static void GetUserHomeDirectory(llvm::SmallVectorImpl& str) { - str.reserve(MAX_PATH); - HRESULT res = SHGetFolderPathA(NULL, - CSIDL_FLAG_CREATE | CSIDL_APPDATA, - NULL, - SHGFP_TYPE_CURRENT, - str.data()); - if (res != S_OK) { - assert(0 && "Failed to get user home directory"); - llvm::StringRef SRhome("\\"); - str.insert(str.begin(), SRhome.begin(), SRhome.end()); - } - } -#else -# error "Unsupported platform." -#endif -} - namespace { ///\brief Class that specialises the textinput TabCompletion to allow Cling /// to code complete through its own textinput mechanism which is part of the @@ -122,9 +88,8 @@ namespace cling { llvm::SmallString<512> histfilePath; if (!getenv("CLING_NOHISTORY")) { // History file is $HOME/.cling_history - static const char* histfile = ".cling_history"; - GetUserHomeDirectory(histfilePath); - llvm::sys::path::append(histfilePath, histfile); + if (llvm::sys::path::home_directory(histfilePath)) + llvm::sys::path::append(histfilePath, ".cling_history"); } using namespace textinput;