[PATCH] D14446: Fallback to getpwuid() in path::home_directory() on Unix.
Aaron Ballman via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 25 06:40:11 PST 2015
aaron.ballman added inline comments.
================
Comment at: lib/Support/Unix/Path.inc:558
@@ +557,3 @@
+#ifdef HAVE_PWD_H
+ static const size_t InitialBufSize = 1024;
+ SmallString<InitialBufSize> Buf;
----------------
chfast wrote:
> aaron.ballman wrote:
> > Why 1024?
> It is suggested initial buffer size returned by `sysconf(_SC_GETPW_R_SIZE_MAX)`.
Ah, good to know, thank you!
================
Comment at: lib/Support/Unix/Path.inc:584
@@ -554,1 +583,3 @@
+bool home_directory(SmallVectorImpl<char> &Result) {
if (char *RequestedDir = getenv("HOME")) {
+ Result.clear();
----------------
chfast wrote:
> aaron.ballman wrote:
> > Is getpwuid() more reliable than reading the environment variable?
> I don't understand the question. Are you asking which approach is better?
>
> Checking the environmental variable first allows the user change home directory location visible by the application.
I was under the impression (which may be incorrect) that getpwuid() was a safer, more reliable way to get the home directory, when the API is available, and the environment variable is more of a backup plan. If that is true, it would make sense to call getHomeDirFromPasswd() first, and fallback to getenv().
http://reviews.llvm.org/D14446
More information about the llvm-commits
mailing list