summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-09-30 02:43:25 +0000
committerJune McEnroe <june@causal.agency>2021-09-30 02:43:25 +0000
commitc428697491dd57f4b2335cf74ec0cc8759583a55 (patch)
treed4ed5ccaedc04fe5f532c2b9c02c9bd11f0236f3
parentpledge(2) hilex (diff)
downloadsrc-c428697491dd57f4b2335cf74ec0cc8759583a55.tar.gz
src-c428697491dd57f4b2335cf74ec0cc8759583a55.zip
pledge(2) htagml
Diffstat (limited to '')
-rw-r--r--bin/htagml.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/bin/htagml.c b/bin/htagml.c
index 3d112b46..04dd5928 100644
--- a/bin/htagml.c
+++ b/bin/htagml.c
@@ -81,10 +81,10 @@ int main(int argc, char *argv[]) {
 	bool pre = false;
 	bool pipe = false;
 	bool index = false;
-	const char *tagsFile = "tags";
+	const char *tagsPath = "tags";
 	for (int opt; 0 < (opt = getopt(argc, argv, "f:ipx"));) {
 		switch (opt) {
-			break; case 'f': tagsFile = optarg;
+			break; case 'f': tagsPath = optarg;
 			break; case 'i': pipe = true;
 			break; case 'p': pre = true;
 			break; case 'x': index = true;
@@ -94,8 +94,16 @@ int main(int argc, char *argv[]) {
 	if (optind == argc) errx(EX_USAGE, "name required");
 	const char *name = argv[optind];
 
-	FILE *file = fopen(tagsFile, "r");
-	if (!file) err(EX_NOINPUT, "%s", tagsFile);
+	FILE *file = fopen(name, "r");
+	if (!file) err(EX_NOINPUT, "%s", name);
+
+	FILE *tagsFile = fopen(tagsPath, "r");
+	if (!tagsFile) err(EX_NOINPUT, "%s", tagsPath);
+
+#ifdef __OpenBSD__
+	int error = pledge("stdio", NULL);
+	if (error) err(EX_OSERR, "pledge");
+#endif
 
 	size_t len = 0;
 	size_t cap = 256;
@@ -109,7 +117,7 @@ int main(int argc, char *argv[]) {
 
 	char *buf = NULL;
 	size_t bufCap = 0;
-	while (0 < getline(&buf, &bufCap, file)) {
+	while (0 < getline(&buf, &bufCap, tagsFile)) {
 		char *line = buf;
 		char *tag = strsep(&line, "\t");
 		char *file = strsep(&line, "\t");
@@ -142,10 +150,7 @@ int main(int argc, char *argv[]) {
 		}
 		len++;
 	}
-	fclose(file);
-
-	file = fopen(name, "r");
-	if (!file) err(EX_NOINPUT, "%s", name);
+	fclose(tagsFile);
 
 	int num = 0;
 	printf(pre ? "<pre>" : index ? "<ul class=\"index\">\n" : "");