From d99f20c0ff5ef7fb274a09de22b515749be9c7ec Mon Sep 17 00:00:00 2001 From: C. McEnroe Date: Wed, 25 Mar 2020 18:56:09 -0400 Subject: Add logging functions The mkdir dance is a bit awkward... --- xdg.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'xdg.c') 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); +} -- cgit 1.4.1-2-gfad0