Reimplement GetUserHomeDirectory().

This commit is contained in:
Axel Naumann 2013-09-19 16:54:21 +02:00 committed by sftnight
parent 3f5ba7edc6
commit 6c0e0a2103

View File

@ -16,7 +16,8 @@
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/PathV1.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/SmallString.h"
#include "llvm/Config/config.h"
// Fragment copied from LLVM's raw_ostream.cpp
@ -24,6 +25,10 @@
# include <unistd.h>
#endif
#if defined(LLVM_ON_WIN32)
#include <Shlobj.h>
#endif
#if defined(_MSC_VER)
#ifndef STDIN_FILENO
# define STDIN_FILENO 0
@ -45,6 +50,30 @@ namespace {
bool /*gen_crash_diag*/) {
throw cling::CompilationException(reason);
}
#if defined(LLVM_ON_UNIX)
static void GetUserHomeDirectory(llvm::SmallVectorImpl<char>& str) {
if (const char* home = getenv("HOME"))
str = home;
} else {
str = "/";
}
}
#elif defined(LLVM_ON_WIN32)
static void GetUserHomeDirectory(llvm::SmallVectorImpl<char>& 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");
str = "/";
}
}
#else
# error "Unsupported platform."
#endif
}
namespace cling {
@ -69,8 +98,9 @@ namespace cling {
// History file is $HOME/.cling_history
static const char* histfile = ".cling_history";
llvm::sys::Path histfilePath = llvm::sys::Path::GetUserHomeDirectory();
histfilePath.appendComponent(histfile);
llvm:SmallString<512> histfilePath;
GetUserHomeDirectory(histfilePath);
llvm::sys::fs::append(histfilePath, histfile);
using namespace textinput;
StreamReader* R = StreamReader::Create();