aboutsummaryrefslogtreecommitdiff
path: root/src/config.c
blob: f69164855bcaf009f085f55e57b6bd4ca28e8869 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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);
    }
}