aboutsummaryrefslogtreecommitdiff
path: root/src/config.c
blob: ebaff3eb718f34e8969f2e02ead1ec4a1953e9e8 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <string.h>
#include <stdio.h>

#include <sys/stat.h>
#include <sys/types.h>

#include "config.h"
#include "common.h"

#ifdef _WIN32
#define HOMEVAR "USERPROFILE"
#else
#define HOMEVAR "HOME"
#endif

static void getXDGDir(const char* envvar, const char* homeext, char* config, const size_t size)
{
    char* xdg_var = getenv(envvar);

    if (xdg_var)
    {
        strncpy(config, xdg_var, size);
    }
    else
    {
        char* home = getenv(HOMEVAR);
        if (!home) home = "";
        strncpy(config, home, size);
        strncat(config, homeext, size - strlen(config));
    }
}

void getConfigDir(char* config, const size_t size)
{
    getXDGDir("XDG_CONFIG_HOME", "/.config/" NAME, config, size);
}

void getDataDir(char* config, const size_t size)
{
    getXDGDir("XDG_DATA_HOME", "/.local/share/" NAME, config, size);
}

void getCacheDir(char* config, const size_t size)
{
    getXDGDir("XDG_CACHE_HOME", "/.cache/" NAME, config, size);
}

void getWineDir(char* config, const size_t size)
{
    getDataDir(config, size);
    strncat(config, "/wine", size - strlen(config) - 1);
}

void getDXVKDir(char* config, const size_t size)
{
    getDataDir(config, size);
    strncat(config, "/dxvk", size - strlen(config) - 1);
}