summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Unix
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2017-03-22 15:24:59 +0000
committerZachary Turner <zturner@google.com>2017-03-22 15:24:59 +0000
commita3cf70bfa0f11d7da90f11e148be8f9c285c79ac (patch)
tree475cc356d0425942d77062c822a0c4f531c2c0d2 /llvm/lib/Support/Unix
parent50a066b3138a2cda4be733fdc51b35aaf631bfce (diff)
downloadbcm5719-llvm-a3cf70bfa0f11d7da90f11e148be8f9c285c79ac.tar.gz
bcm5719-llvm-a3cf70bfa0f11d7da90f11e148be8f9c285c79ac.zip
Make home_directory look in the password database in addition to $HOME.
This is something of an edge case, but when the $HOME environment variable is not set, we can still look in the password database to get the current user's home directory. Added a test for this by getting the value of $HOME, then unsetting it, then calling home_directory() and verifying that it succeeds and that the value is the same as what we originally read from the environment. llvm-svn: 298513
Diffstat (limited to 'llvm/lib/Support/Unix')
-rw-r--r--llvm/lib/Support/Unix/Path.inc16
1 files changed, 11 insertions, 5 deletions
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
index 7a5816ba1dd..93f8982196b 100644
--- a/llvm/lib/Support/Unix/Path.inc
+++ b/llvm/lib/Support/Unix/Path.inc
@@ -920,12 +920,18 @@ std::error_code real_path(const Twine &path, SmallVectorImpl<char> &dest,
namespace path {
bool home_directory(SmallVectorImpl<char> &result) {
- if (char *RequestedDir = getenv("HOME")) {
- result.clear();
- result.append(RequestedDir, RequestedDir + strlen(RequestedDir));
- return true;
+ char *RequestedDir = getenv("HOME");
+ if (!RequestedDir) {
+ struct passwd *pw = getpwuid(getuid());
+ if (pw && pw->pw_dir)
+ RequestedDir = pw->pw_dir;
}
- return false;
+ if (!RequestedDir)
+ return false;
+
+ result.clear();
+ result.append(RequestedDir, RequestedDir + strlen(RequestedDir));
+ return true;
}
static bool getDarwinConfDir(bool TempDir, SmallVectorImpl<char> &Result) {
OpenPOWER on IntegriCloud