<div dir="ltr">We probably don't want to silently mutate the environment (which could lead to surprises), but calling a proper system library function to get the home directory makes sense.<div><br></div><div>-- Sean Silva</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 19, 2016 at 11:18 AM, Greg Clayton via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I recently was using llvm code from a process that I manually spawned as a child process and noticed that llvm::sys::path::home_directory() only works if "HOME" is set in the process environment:<br>
<br>
bool home_directory(SmallVectorImpl<char> &result) {<br>
if (char *RequestedDir = getenv("HOME")) {<br>
result.clear();<br>
result.append(RequestedDir, RequestedDir + strlen(RequestedDir));<br>
return true;<br>
}<br>
<br>
return false;<br>
}<br>
<br>
This is in lib/Support/Unix/Path.inc. Do we want to try a little bit harder? Maybe something like:<br>
<br>
bool home_directory(SmallVectorImpl<char> &result) {<br>
if (char *RequestedDir = getenv("HOME")) {<br>
result.clear();<br>
result.append(RequestedDir, RequestedDir + strlen(RequestedDir));<br>
return true;<br>
} else {<br>
struct passwd *pw = getpwuid(getuid());<br>
if (pw && pw->pw_dir && pw->pw_dir[0])<br>
{<br>
setenv("HOME", pw->pw_dir, 0);<br>
result.assign(llvm::StringRef(pw->pw_dir));<br>
return true;<br>
}<br>
}<br>
return false;<br>
}<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br></div>