summaryrefslogtreecommitdiffstats
path: root/thumbs.c
diff options
context:
space:
mode:
authorBert Münnich <ber.t@posteo.de>2014-01-11 22:47:41 +0100
committerBert Münnich <ber.t@posteo.de>2014-01-11 22:47:41 +0100
commit304fd382db98a6a134e0e281cc6f4cf27fb0789a (patch)
tree46dd071885ac75211ecf5c1e2fb235e7549c9a4c /thumbs.c
parent48954a163a009200cc99498e13efec041c92a74b (diff)
downloadnsxiv-304fd382db98a6a134e0e281cc6f4cf27fb0789a.tar.zst
Adhere to XDG Base Directory Specification; fixes issue #124
Diffstat (limited to 'thumbs.c')
-rw-r--r--thumbs.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/thumbs.c b/thumbs.c
index 2090102..fe0ad84 100644
--- a/thumbs.c
+++ b/thumbs.c
@@ -34,7 +34,6 @@
static const int thumb_dim = THUMB_SIZE + 10;
-static const char * const CACHE_DIR = ".sxiv/cache";
static char *cache_dir = NULL;
bool tns_cache_enabled(void)
@@ -163,7 +162,7 @@ void tns_clean_cache(tns_t *tns)
void tns_init(tns_t *tns, int cnt, win_t *win)
{
int len;
- char *homedir;
+ const char *homedir, *dsuffix = "";
if (tns == NULL)
return;
@@ -181,12 +180,16 @@ void tns_init(tns_t *tns, int cnt, win_t *win)
tns->alpha = !RENDER_WHITE_ALPHA;
tns->dirty = false;
- if ((homedir = getenv("HOME")) != NULL) {
+ if ((homedir = getenv("XDG_CACHE_HOME")) == NULL || homedir[0] == '\0') {
+ homedir = getenv("HOME");
+ dsuffix = "/.cache";
+ }
+ if (homedir != NULL) {
if (cache_dir != NULL)
free(cache_dir);
- len = strlen(homedir) + strlen(CACHE_DIR) + 2;
+ len = strlen(homedir) + strlen(dsuffix) + 6;
cache_dir = (char*) s_malloc(len);
- snprintf(cache_dir, len, "%s/%s", homedir, CACHE_DIR);
+ snprintf(cache_dir, len, "%s%s/sxiv", homedir, dsuffix);
} else {
warn("could not locate thumbnail cache directory");
}