pathut: give $HOME priority over pwd entry

This commit is contained in:
Jean-Francois Dockes 2022-09-11 08:49:08 +02:00
parent 5fc0066a34
commit cadfabc3b1

View File

@ -666,19 +666,16 @@ string path_home()
path_catslash(dir); path_catslash(dir);
return dir; return dir;
#else #else
uid_t uid = getuid();
struct passwd *entry = getpwuid(uid);
if (entry == 0) {
const char *cp = getenv("HOME"); const char *cp = getenv("HOME");
if (cp) { if (nullptr == cp) {
return cp; uid_t uid = getuid();
} else { struct passwd *entry = getpwuid(uid);
if (nullptr == entry) {
return "/"; return "/";
} }
cp = entry->pw_dir;
} }
string homedir{cp};
string homedir = entry->pw_dir;
path_catslash(homedir); path_catslash(homedir);
return homedir; return homedir;
#endif #endif