aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2019-09-07 03:50:59 +0200
committerache <ache@ache.one>2019-09-07 03:50:59 +0200
commitbd61c8e48e6eea67190d164de4c960e50bb3909e (patch)
tree07af0e5a0f21c14cd6fc2eeb8e7b8c1e268ee975
parentOups sms.o (diff)
Better detect user HOME
-rw-r--r--config.h3
-rw-r--r--readConfig.c9
2 files changed, 11 insertions, 1 deletions
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<sys/types.h>
+#include<pwd.h>
+
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 ) {