diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2022-08-14 19:58:03 +0200 |
---|---|---|
committer | BenBE <BenBE@geshi.org> | 2022-08-22 21:32:49 +0200 |
commit | 62d59403d92abaf256604bfc17e76c85ce64ea35 (patch) | |
tree | d863afd15fb7c091d826907f9b310803a6035e7f /Settings.c | |
parent | 5aa207f9af6622583fd60edebaef1c3ed19ab91d (diff) |
Add fallback for HOME environment variable
If the environment variable HOME is not set, try to get the home
directory from the systems password database.
Diffstat (limited to 'Settings.c')
-rw-r--r-- | Settings.c | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -10,6 +10,7 @@ in the source distribution for its full text. #include <ctype.h> #include <errno.h> #include <limits.h> +#include <pwd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -702,9 +703,10 @@ Settings* Settings_new(unsigned int initialCpuCount, Hashtable* dynamicColumns) this->filename = xStrdup(rcfile); } else { const char* home = getenv("HOME"); - if (!home) - home = ""; - + if (!home) { + const struct passwd* pw = getpwuid(getuid()); + home = pw ? pw->pw_dir : ""; + } const char* xdgConfigHome = getenv("XDG_CONFIG_HOME"); char* configDir = NULL; char* htopDir = NULL; |