From bd61c8e48e6eea67190d164de4c960e50bb3909e Mon Sep 17 00:00:00 2001 From: ache Date: Sat, 7 Sep 2019 03:50:59 +0200 Subject: Better detect user HOME --- config.h | 3 +++ readConfig.c | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/config.h b/config.h index d053bc7..8779606 100644 --- a/config.h +++ b/config.h @@ -1,6 +1,9 @@ #ifndef CONFIG_H #define CONFIG_H +#include +#include + typedef struct config_t { char SMS_INBOX[256]; char SMS_OUTBOX[256]; diff --git a/readConfig.c b/readConfig.c index 3640f65..3497b0e 100644 --- a/readConfig.c +++ b/readConfig.c @@ -48,7 +48,14 @@ int searchConfigFile(char* configFile) { #endif // Home first - sprintf(path, "%s/.mesmsrc", getenv("HOME")); + char* home; + struct passwd* pw = getpwuid(getuid()); + home = pw->pw_dir; + + if( !*home ) + home = getenv("HOME"); + + sprintf(path, "%s/.mesmsrc", home); f_canRead = fopen(path, "r"); if( f_canRead ) { -- cgit v1.2.3