This is an archive of the discontinued LLVM Phabricator instance.

Introduce llvm::sys::path::home_directory.
ClosedPublic

Authored by pcc on Nov 17 2013, 2:55 AM.

Details

Summary

This will be used by the line editor library to derive a default path to
the history file.

I've verified that the Windows bits build (with a mingw64 cross compiler)
but I haven't actually tested them.

Diff Detail

Event Timeline

majnemer added inline comments.Nov 17 2013, 3:53 AM
lib/Support/Unix/Path.inc
805 ↗(On Diff #5601)

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;

SHGetFolderPath is Deprecated function, Microsoft suggests to use SHGetKnownFolderPath instead.

http://msdn.microsoft.com/en-us/library/windows/desktop/bb762181(v=vs.85).aspx

In any case, the easy way to get the AppData directory is getenv("LOCALAPPDATA").

pcc updated this revision to Unknown Object (????).Nov 17 2013, 2:33 PM
  • Clear result on success
lib/Support/Unix/Path.inc
805 ↗(On Diff #5601)

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.

pcc closed this revision.Jan 31 2014, 3:52 PM

Closed by commit rL200594 (authored by @pcc).