If even HOME is missing look up the user's home directory from passwd

Signed-off-by: Mattias Andrée <maandree@operamail.com>
This commit is contained in:
Mattias Andrée
2014-03-11 17:57:30 +01:00
parent e26337db2e
commit f5a7d6e393
+12
View File
@@ -22,6 +22,10 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#ifndef _WIN32
# include <pwd.h>
# include <unistd.h>
#endif
#include "config-ini.h"
@@ -59,6 +63,14 @@ open_config_file(const char *filepath)
snprintf(cp, sizeof(cp),
"%s/.config/redshift.conf", env);
filepath = cp;
#ifndef _WIN32
} else {
struct passwd *pwd = getpwuid(getuid());
char *home = pwd->pw_dir;
snprintf(cp, sizeof(cp),
"%s/.config/redshift.conf", home);
filepath = cp;
#endif
}
if (filepath != NULL) {