about summary refs log tree commit diff
path: root/xdg.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-03-25 18:56:09 -0400
committerJune McEnroe <june@causal.agency>2020-03-25 18:56:09 -0400
commitd99f20c0ff5ef7fb274a09de22b515749be9c7ec (patch)
treec7ec58d4d8fa21732cd9459b6477d2ecb6ef055d /xdg.c
parentTrack MODE in replies (diff)
downloadcatgirl-d99f20c0ff5ef7fb274a09de22b515749be9c7ec.tar.gz
catgirl-d99f20c0ff5ef7fb274a09de22b515749be9c7ec.zip
Add logging functions
The mkdir dance is a bit awkward...
Diffstat (limited to 'xdg.c')
-rw-r--r--xdg.c22
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);
+}