diff options
author | June McEnroe <june@causal.agency> | 2020-03-25 18:56:09 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-03-25 18:56:09 -0400 |
commit | d99f20c0ff5ef7fb274a09de22b515749be9c7ec (patch) | |
tree | c7ec58d4d8fa21732cd9459b6477d2ecb6ef055d /xdg.c | |
parent | Track MODE in replies (diff) | |
download | test-d99f20c0ff5ef7fb274a09de22b515749be9c7ec.tar.gz test-d99f20c0ff5ef7fb274a09de22b515749be9c7ec.zip |
Add logging functions
The mkdir dance is a bit awkward...
Diffstat (limited to '')
-rw-r--r-- | xdg.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/xdg.c b/xdg.c index ed2a6e1..c70873a 100644 --- a/xdg.c +++ b/xdg.c @@ -134,3 +134,25 @@ local: if (!file) warn("%s", path); return file; } + +void dataMkdir(const char *path) { + const char *home = getenv("HOME"); + const char *dataHome = getenv("XDG_DATA_HOME"); + + char homePath[PATH_MAX]; + if (dataHome) { + snprintf( + homePath, sizeof(homePath), + "%s/" SUBDIR "/%s", dataHome, path + ); + } else { + if (!home) return; + snprintf( + homePath, sizeof(homePath), + "%s/.local/share/" SUBDIR "/%s", home, path + ); + } + + int error = mkdir(homePath, S_IRWXU); + if (error && errno != EEXIST) warn("%s", homePath); +} |