diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2014-01-31 23:46:06 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2014-01-31 23:46:06 +0000 |
commit | bef2236283c333f17613b2ea4904878228fedb6e (patch) | |
tree | 0cd1ac4a44a055999bc0cdf6fb08717d341b44e9 /lib | |
parent | f10743d765c456db7c9cd2a9fe4c528d75bb5b8f (diff) | |
download | llvm-bef2236283c333f17613b2ea4904878228fedb6e.tar.gz llvm-bef2236283c333f17613b2ea4904878228fedb6e.tar.bz2 llvm-bef2236283c333f17613b2ea4904878228fedb6e.tar.xz |
Introduce llvm::sys::path::home_directory.
This will be used by the line editor library to derive a default path to
the history file.
Differential Revision: http://llvm-reviews.chandlerc.com/D2199
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200594 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Support/Unix/Path.inc | 15 | ||||
-rw-r--r-- | lib/Support/Windows/Path.inc | 17 |
2 files changed, 32 insertions, 0 deletions
diff --git a/lib/Support/Unix/Path.inc b/lib/Support/Unix/Path.inc index d526042461..d0b63b5ba5 100644 --- a/lib/Support/Unix/Path.inc +++ b/lib/Support/Unix/Path.inc @@ -797,5 +797,20 @@ error_code openFileForWrite(const Twine &Name, int &ResultFD, } } // end namespace fs + +namespace path { + +bool home_directory(SmallVectorImpl<char> &result) { + if (char *RequestedDir = getenv("HOME")) { + result.clear(); + result.append(RequestedDir, RequestedDir + strlen(RequestedDir)); + return true; + } + + return false; +} + +} // end namespace path + } // end namespace sys } // end namespace llvm diff --git a/lib/Support/Windows/Path.inc b/lib/Support/Windows/Path.inc index 4ef7285801..e218fa2e72 100644 --- a/lib/Support/Windows/Path.inc +++ b/lib/Support/Windows/Path.inc @@ -19,6 +19,7 @@ #include "llvm/ADT/STLExtras.h" #include <fcntl.h> #include <io.h> +#include <shlobj.h> #include <sys/stat.h> #include <sys/types.h> @@ -1063,6 +1064,22 @@ error_code openFileForWrite(const Twine &Name, int &ResultFD, } } // end namespace fs +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, Path) != S_OK) + return false; + + if (UTF16ToUTF8(Path, ::wcslen(Path), result)) + return false; + + return true; +} + +} // end namespace path + namespace windows { llvm::error_code UTF8ToUTF16(llvm::StringRef utf8, llvm::SmallVectorImpl<wchar_t> &utf16) { |