From b3671b4779ec432f76e42743fa5130844d2829a3 Mon Sep 17 00:00:00 2001 From: fekir Date: Tue, 31 Oct 2017 14:33:14 +0100 Subject: [PATCH 1/2] Add function for querying location of configure files --- tmux.c | 28 ++++++++++++++++++++++++++++ tmux.h | 1 + 2 files changed, 29 insertions(+) diff --git a/tmux.c b/tmux.c index f9de920c..e30c8b1e 100644 --- a/tmux.c +++ b/tmux.c @@ -208,6 +208,34 @@ find_home(void) return (home); } +const char * +find_config_dir(const char* home) +{ + const char default_dir_rel_to_home[] = "/.config"; + static char *config_dir; + + if (config_dir != NULL){ + return (config_dir); + } + + config_dir = getenv("XDG_CONFIG_HOME"); + if (config_dir != NULL && *config_dir != '\0') { + return config_dir; + } + + // fallback to default location + if(home == NULL){ + return NULL; + } + + config_dir = malloc(strlen(home)+ strlen(default_dir_rel_to_home) + 1); + if(config_dir != NULL){ + strcpy( config_dir, home ) ; + strcat( config_dir, default_dir_rel_to_home ) ; + } + return config_dir; +} + int main(int argc, char **argv) { diff --git a/tmux.h b/tmux.h index 9bf9f933..9d59bf84 100644 --- a/tmux.h +++ b/tmux.h @@ -1697,6 +1697,7 @@ int areshell(const char *); void setblocking(int, int); const char *find_cwd(void); const char *find_home(void); +const char *find_config_dir(const char* home); /* proc.c */ struct imsg; -- 2.23.0