summary refs log tree commit diff
path: root/litterbox.h
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-12-01 20:21:46 -0500
committerJune McEnroe <june@causal.agency>2019-12-01 20:21:46 -0500
commit0414263ca5e2ef787df03b14b1a9748b350f3012 (patch)
tree93e9c65f11038ddb1f556b0663194abdbc51c1e0 /litterbox.h
parentImplement database file search (diff)
downloadlitterbox-0414263ca5e2ef787df03b14b1a9748b350f3012.tar.gz
litterbox-0414263ca5e2ef787df03b14b1a9748b350f3012.zip
Add XDG_DATA_DIRS default value
Diffstat (limited to 'litterbox.h')
-rw-r--r--litterbox.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/litterbox.h b/litterbox.h
index 48d707c..07d4bbc 100644
--- a/litterbox.h
+++ b/litterbox.h
@@ -48,15 +48,19 @@ static inline sqlite3 *dbOpen(int flags) {
 	const char *home = getenv("HOME");
 	const char *dataHome = getenv("XDG_DATA_HOME");
 	const char *dataDirs = getenv("XDG_DATA_DIRS");
+
 	char path[PATH_MAX];
 	if (dataHome) {
 		snprintf(path, sizeof(path), "%s/" DATABASE_PATH, dataHome);
 	} else {
+		if (!home) errx(EX_CONFIG, "HOME unset");
 		snprintf(path, sizeof(path), "%s/.local/share/" DATABASE_PATH, home);
 	}
 	sqlite3 *db = dbOpenPath(path, flags);
 	if (db) return db;
-	while (dataDirs && *dataDirs) {
+
+	if (!dataDirs) dataDirs = "/usr/local/share:/usr/share";
+	while (*dataDirs) {
 		size_t len = strcspn(dataDirs, ":");
 		snprintf(path, sizeof(path), "%.*s/" DATABASE_PATH, (int)len, dataDirs);
 		db = dbOpenPath(path, flags);