diff options
Diffstat (limited to 'src/config.c')
-rw-r--r-- | src/config.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/config.c b/src/config.c new file mode 100644 index 0000000..f691648 --- /dev/null +++ b/src/config.c @@ -0,0 +1,44 @@ +#include <string.h> +#include <stdio.h> + +#include <sys/stat.h> +#include <sys/types.h> + +#include "config.h" +#include "common.h" + +void getXDGDir(const char* envvar, const char* homeext, char* config) +{ + char* xdg_var = getenv(envvar); + + if (xdg_var) + { + strcpy(config, xdg_var); + } + else + { + char* home = getenv("HOME"); + strcpy(config, home); + strcat(config, homeext); + } +} + +void getConfigDir(char* config) +{ + getXDGDir("XDG_CONFIG_HOME", "/.config/" NAME, config); +} + +void getDataDir(char* config) +{ + getXDGDir("XDG_DATA_HOME", "/.local/share/" NAME, config); +} + +void makeDir(const char* path) +{ + struct stat st = {0}; + + if (stat(path, &st) == -1) + { + mkdir(path, 0755); + } +}
\ No newline at end of file |