summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--xdg.c37
1 files changed, 12 insertions, 25 deletions
diff --git a/xdg.c b/xdg.c
index c706e87..b206427 100644
--- a/xdg.c
+++ b/xdg.c
@@ -71,7 +71,7 @@ basePath(struct Base base, const char **dirs, const char *path) {
 		return buf;
 	}
 
-	if (path[0] == '/' || path[0] == '.') {
+	if (path[strspn(path, ".")] == '/') {
 		*dirs = "";
 		return path;
 	}
@@ -89,7 +89,7 @@ basePath(struct Base base, const char **dirs, const char *path) {
 			home, base.defHome, path
 		);
 	} else {
-		return NULL;
+		errx(EX_CONFIG, "HOME unset");
 	}
 	return buf;
 }
@@ -98,8 +98,7 @@ const char *configPath(const char **dirs, const char *path) {
 	return basePath(Config, dirs, path);
 }
 
-const char *
-dataPath(const char **dirs, const char *path) {
+const char *dataPath(const char **dirs, const char *path) {
 	return basePath(Data, dirs, path);
 }
 
@@ -110,17 +109,16 @@ FILE *configOpen(const char *path, const char *mode) {
 		if (file) return file;
 		if (errno != ENOENT) warn("%s", abs);
 	}
-	FILE *file = fopen(path, mode);
-	if (!file) warn("%s", path);
-	return file;
+	dirs = NULL;
+	warn("%s", configPath(&dirs, path));
+	return NULL;
 }
 
 void dataMkdir(const char *path) {
 	const char *dirs = NULL;
-	const char *abs = dataPath(&dirs, path);
-	if (!abs) return;
-	int error = mkdir(abs, S_IRWXU);
-	if (error && errno != EEXIST) warn("%s", abs);
+	path = dataPath(&dirs, path);
+	int error = mkdir(path, S_IRWXU);
+	if (error && errno != EEXIST) warn("%s", path);
 }
 
 FILE *dataOpen(const char *path, const char *mode) {
@@ -130,20 +128,9 @@ FILE *dataOpen(const char *path, const char *mode) {
 		if (file) return file;
 		if (errno != ENOENT) warn("%s", abs);
 	}
-
-	if (mode[0] != 'r') {
-		dataMkdir("");
-		dirs = NULL;
-		path = dataPath(&dirs, path);
-		if (!path) {
-			warn("HOME unset");
-			return NULL;
-		}
-		FILE *file = fopen(path, mode);
-		if (!file) warn("%s", path);
-		return file;
-	}
-
+	if (mode[0] != 'r') dataMkdir("");
+	dirs = NULL;
+	path = dataPath(&dirs, path);
 	FILE *file = fopen(path, mode);
 	if (!file) warn("%s", path);
 	return file;
d=9298fe810211ea3cd5bf6fdbb76b115f28ae2491&follow=1'>Handle subshells (and functions) inside substitutionsJune McEnroe 2022-06-10Switch to jorts Install scriptJune McEnroe 2022-06-08Indicate if still reading or no resultsJune McEnroe 2022-06-08Add Maiden, Mother, CroneJune McEnroe 2022-06-05FIRST SHOW IN 2.5 YEARS BABEY!!!June McEnroe 2022-06-03Set line number on File linesJune McEnroe 2022-06-03Stop polling stdin after EOFJune McEnroe 2022-06-02Set TABSIZE=4June McEnroe 2022-06-02Do basic match highlightingJune McEnroe 2022-06-02Clean up parsing a littleJune McEnroe 2022-06-02Don't duplicate path stringJune McEnroe 2022-06-02Use stderr instead of /dev/tty, realloc buffer if lines too longJune McEnroe 2022-06-02Add initial working version of qfJune McEnroe 2022-05-29Set prompt for okshJune McEnroe