Index: lib/Support/Unix/Path.inc =================================================================== --- lib/Support/Unix/Path.inc +++ lib/Support/Unix/Path.inc @@ -44,6 +44,7 @@ # include # endif #endif +#include #ifdef __APPLE__ #include @@ -546,7 +547,19 @@ namespace path { bool home_directory(SmallVectorImpl &result) { - if (char *RequestedDir = getenv("HOME")) { + char *RequestedDir = getenv("HOME"); + if (!RequestedDir) + { + struct passwd Pwd, *PwdResult = NULL; + long BufSize = sysconf(_SC_GETPW_R_SIZE_MAX); + if (BufSize == -1) + BufSize = 1024; + char Buf[BufSize]; + getpwuid_r(getuid(), &Pwd, Buf, BufSize, &PwdResult); + if (PwdResult) + RequestedDir = PwdResult->pw_dir; + } + if (RequestedDir) { result.clear(); result.append(RequestedDir, RequestedDir + strlen(RequestedDir)); return true;