diff options
author | Jan200101 <sentrycraft123@gmail.com> | 2020-07-31 16:24:59 +0200 |
---|---|---|
committer | Jan200101 <sentrycraft123@gmail.com> | 2020-07-31 16:24:59 +0200 |
commit | aabfdfe3fcbcf718b30872c98568581d7e7e6cca (patch) | |
tree | b8b1d94814c9d339c6d6bb019f1fff9e4ccb2406 /src/config.c | |
parent | 83e4ea0f70ba75f337615ee847f85d4be630686b (diff) | |
download | polecat-aabfdfe3fcbcf718b30872c98568581d7e7e6cca.tar.gz polecat-aabfdfe3fcbcf718b30872c98568581d7e7e6cca.zip |
implement config dirs and unpack tars to them0.1.1
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 |