about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-01-26 15:39:13 -0500
committerJune McEnroe <june@causal.agency>2021-01-26 15:51:40 -0500
commite89e6dda99fbc3d0d952da5692014326f8cf7a74 (patch)
tree276955f47f690eccda6956fd6bd928300c4e4698
parentExpand the opening paragraph of the manual (diff)
downloadcatgirl-e89e6dda99fbc3d0d952da5692014326f8cf7a74.tar.gz
catgirl-e89e6dda99fbc3d0d952da5692014326f8cf7a74.zip
Tighten up XDG base directory path handling
Don't search base directories if path starts with "/", "./" or
"../", but still do if the path simply starts with ".". Bail early
if HOME is needed but unset. Don't attempt to open the original
path in configOpen and dataOpen.
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;
rom September 29June McEnroe 2024-10-07Add photos from September 28June McEnroe 2024-10-07Add photos from September 22June McEnroe 2024-09-25Add photos from September 15June McEnroe 2024-09-24Add photos from September 14June McEnroe 2024-09-24Add photos from September 12June McEnroe 2024-09-24Add photos from September 7June McEnroe 2024-09-24Allow not having descriptionsJune McEnroe I'm sorry, I can't keep writing descriptions. It makes posting photos take too long, I often don't know the words for what I'm looking at, and a good description is an entirely different work of art than the photo I took, and I'm just a photographer. It's visual art. 2024-09-23Automatically select the last used lens for a bodyJune McEnroe 2024-09-19Add photos from September 5June McEnroe Had to prefix the folder number onto these file names manually because they must have come out of a different scanner or something. 2024-09-15Add some more film stocks to the listJune McEnroe 2024-09-13Add photos from September 2June McEnroe 2024-09-13Add Fomapan 200 to films listJune McEnroe 2024-09-10Add August 29 picnic photosJune McEnroe 2024-09-08Apply some bold to trips renderingJune McEnroe This seems easier to visually scan. The only other thing I'd like is a nicer date rendering but JavaScript is useless for that. 2024-09-08Render trips hopefully more efficientlyJune McEnroe 2024-09-08Allow removing bodies and lensesJune McEnroe 2024-09-08Limit body width so it looks less silly on desktopJune McEnroe 2024-09-07Handle no film being loadedJune McEnroe 2024-09-07Fancy up the text a littleJune McEnroe