[PATCH] Fix llvm::sys::path::home_directory on unix to get path from passwd.pw_dir when the $HOME variable isn't set

Ilia K ki.stfu at gmail.com
Mon Feb 9 11:17:20 PST 2015


This patch adds alternative way to get the user's home directory.

REPOSITORY
  rL LLVM

http://reviews.llvm.org/D7515

Files:
  lib/Support/Unix/Path.inc

Index: lib/Support/Unix/Path.inc
===================================================================
--- lib/Support/Unix/Path.inc
+++ lib/Support/Unix/Path.inc
@@ -44,6 +44,7 @@
 #  include <ndir.h>
 # endif
 #endif
+#include <pwd.h>
 
 #ifdef __APPLE__
 #include <mach-o/dyld.h>
@@ -546,7 +547,10 @@
 namespace path {
 
 bool home_directory(SmallVectorImpl<char> &result) {
-  if (char *RequestedDir = getenv("HOME")) {
+  char *RequestedDir = getenv("HOME");
+  if (!RequestedDir)
+    RequestedDir = getpwuid(getuid())->pw_dir;
+  if (RequestedDir) {
     result.clear();
     result.append(RequestedDir, RequestedDir + strlen(RequestedDir));
     return true;

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7515.19601.patch
Type: text/x-patch
Size: 665 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150209/810137e0/attachment.bin>


More information about the llvm-commits mailing list