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(); const char *cp = getenv("HOME");
if (nullptr == cp) {
struct passwd *entry = getpwuid(uid); uid_t uid = getuid();
if (entry == 0) { struct passwd *entry = getpwuid(uid);
const char *cp = getenv("HOME"); if (nullptr == entry) {
if (cp) {
return cp;
} else {
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