summaryrefslogtreecommitdiffstats
path: root/Settings.c
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2022-08-14 19:58:03 +0200
committerBenBE <BenBE@geshi.org>2022-08-22 21:32:49 +0200
commit62d59403d92abaf256604bfc17e76c85ce64ea35 (patch)
treed863afd15fb7c091d826907f9b310803a6035e7f /Settings.c
parent5aa207f9af6622583fd60edebaef1c3ed19ab91d (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.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/Settings.c b/Settings.c
index 7d6fca47..aefd9e3c 100644
--- a/Settings.c
+++ b/Settings.c
@@ -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;

© 2014-2024 Faster IT GmbH | imprint | privacy policy