Commit 9804997b authored by mk-pmb's avatar mk-pmb

pick home and config path from environment if set.

parent 6132516d
...@@ -151,11 +151,16 @@ void set_terminal_attributes (void) { ...@@ -151,11 +151,16 @@ void set_terminal_attributes (void) {
} }
/* }}} */ /* }}} */
int str_empty (char *str) {
return ((str == NULL) || (strlen(str) < 1));
}
char *get_home_directory (void) { char *get_home_directory (void) {
static char *home_directory = NULL; static char *home_directory = NULL;
if (home_directory != NULL) { home_directory = getenv("TELEGRAM_HOME");
return home_directory; if (!str_empty (home_directory)) { return tstrdup (home_directory); }
} home_directory = getenv("HOME");
if (!str_empty (home_directory)) { return tstrdup (home_directory); }
struct passwd *current_passwd; struct passwd *current_passwd;
uid_t user_id; uid_t user_id;
setpwent (); setpwent ();
...@@ -167,14 +172,14 @@ char *get_home_directory (void) { ...@@ -167,14 +172,14 @@ char *get_home_directory (void) {
} }
} }
endpwent (); endpwent ();
if (home_directory == NULL) { if (str_empty (home_directory)) { home_directory = tstrdup ("."); }
home_directory = tstrdup (".");
}
return home_directory; return home_directory;
} }
char *get_config_directory (void) { char *get_config_directory (void) {
char *config_directory; char *config_directory;
config_directory = getenv("TELEGRAM_CONFIG_DIR");
if (!str_empty (config_directory)) { return tstrdup (config_directory); }
tasprintf (&config_directory, "%s/" CONFIG_DIRECTORY, get_home_directory ()); tasprintf (&config_directory, "%s/" CONFIG_DIRECTORY, get_home_directory ());
return config_directory; return config_directory;
} }
...@@ -249,6 +254,7 @@ void running_for_first_time (void) { ...@@ -249,6 +254,7 @@ void running_for_first_time (void) {
config_file_fd = open (config_filename, O_CREAT | O_RDWR, 0600); config_file_fd = open (config_filename, O_CREAT | O_RDWR, 0600);
if (config_file_fd == -1) { if (config_file_fd == -1) {
perror ("open[config_file]"); perror ("open[config_file]");
printf ("I: config_file=[%s]\n", config_filename);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
if (write (config_file_fd, DEFAULT_CONFIG_CONTENTS, strlen (DEFAULT_CONFIG_CONTENTS)) <= 0) { if (write (config_file_fd, DEFAULT_CONFIG_CONTENTS, strlen (DEFAULT_CONFIG_CONTENTS)) <= 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment