[PATCH] Introduce llvm::sys::path::home_directory.
Peter Collingbourne
peter at pcc.me.uk
Sun Nov 17 14:34:09 PST 2013
================
Comment at: lib/Support/Unix/Path.inc:805
@@ +804,3 @@
+
+ return false;
+}
----------------
David Majnemer wrote:
> Have you considered falling back to `getpwuid_r` on SUSv3? Something like:
> bufsize = 2048;
>
> #ifdef _SC_GETPW_R_SIZE_MAX
> if ((getpw_r_size_max = sysconf(_SC_GETPW_R_SIZE_MAX)) > 0)
> bufsize = (size_t)getpw_r_size_max;
> #endif
>
> uid = getuid();
>
> buf = NULL;
> do {
> if ((tbuf = realloc(buf, bufsize)) == NULL) {
> free(buf);
> return false;
> }
> buf = tbuf;
> err = getpwuid_r(uid, &pw, buf, bufsize, &tpw);
> bufsize *= 2;
> } while (err == ERANGE);
>
> if (err) {
> free(buf);
> return false;
> }
>
> if (!tpw || !pw.pw_dir)
> return false;
>
> result.append(pw.pw_dir, pw.pw_dir + strlen(pw.pw_dir));
> return true;
My understanding (from reading the getpwuid_r man page) is that user programs should be checking $HOME. If $HOME is not set, the user probably doesn't want the program using any directory as their home directory.
http://llvm-reviews.chandlerc.com/D2199
More information about the llvm-commits
mailing list