[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 12:10:47 PST 2015


Hello Chandler,

>RE: Why is this useful?
It tries to get home_direictory by all ways. It's useful in case when HOME
wasn't set (that was in my case).

>RE: The documentation for getpwuid specifically suggests that applications
should merely inspect the HOME environment variable.
I didn't see any references to HOME variable. (see
http://pubs.opengroup.org/onlinepubs/009695399/functions/getpwuid.html)

>RE: If this is truly necessary, it should use getpwuid_r to be
thread-safe, and it should probably be protected by compatibility macros as
I don't know which of the unix variants we support implement this
functionality. But maybe it is sufficiently widely available across BSD,
Linux, Solaris, Unix, and Mac OS variants....
I have updated my patch (now it uses thread-safe function) but I don't know
how to protect the inclusion of pwd.h (HAVE_PWD_H is absent).

Of course I can setup HOME (using getpwuid()) on start but I think that
path::home_directory() should do it for me.

Thanks,
Ilia




On Mon, Feb 9, 2015 at 10:26 PM, Chandler Carruth <chandlerc at google.com>
wrote:

>
> On Mon, Feb 9, 2015 at 11:17 AM, Ilia K <ki.stfu at gmail.com> wrote:
>
>> This patch adds alternative way to get the user's home directory.
>
>
> Why is this useful?
>
> The documentation for getpwuid specifically suggests that applications
> should merely inspect the HOME environment variable.
>
> If this is truly necessary, it should use getpwuid_r to be thread-safe,
> and it should probably be protected by compatibility macros as I don't know
> which of the unix variants we support implement this functionality. But
> maybe it is sufficiently widely available across BSD, Linux, Solaris, Unix,
> and Mac OS variants....
>
> -Chandler
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150209/26e99955/attachment.html>


More information about the llvm-commits mailing list