summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--log.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/log.c b/log.c
index 32d771f..d2f937f 100644
--- a/log.c
+++ b/log.c
@@ -73,6 +73,15 @@ static void logMkdir(const char *path) {
 	if (error && errno != EEXIST) err(EX_CANTCREAT, "log/%s", path);
 }
 
+static void sanitize(char *ptr, char *end) {
+	for (char *ch = ptr; ch < end && *ch == '.'; ++ch) {
+		*ch = '_';
+	}
+	for (char *ch = ptr; ch < end; ++ch) {
+		if (*ch == '/') *ch = '_';
+	}
+}
+
 static struct {
 	int year;
 	int month;
@@ -97,22 +106,21 @@ static FILE *logFile(uint id, const struct tm *tm) {
 	logs[id].month = tm->tm_mon;
 	logs[id].day = tm->tm_mday;
 
-	size_t len = 0;
 	char path[PATH_MAX];
-	for (const char *ch = network.name; *ch; ++ch) {
-		path[len++] = (*ch == '/' ? '_' : *ch);
-	}
-	path[len] = '\0';
+	char *ptr = path, *end = &path[sizeof(path)];
+
+	ptr = seprintf(ptr, end, "%s", network.name);
+	sanitize(path, ptr);
 	logMkdir(path);
 
-	path[len++] = '/';
-	for (const char *ch = idNames[id]; *ch; ++ch) {
-		path[len++] = (*ch == '/' ? '_' : *ch);
-	}
-	path[len] = '\0';
+	char *name = ptr;
+	ptr = seprintf(ptr, end, "/%s", idNames[id]);
+	sanitize(&name[1], ptr);
 	logMkdir(path);
 
-	strftime(&path[len], sizeof(path) - len, "/%F.log", tm);
+	size_t len = strftime(ptr, end - ptr, "/%F.log", tm);
+	if (!len) errx(EX_CANTCREAT, "log path too long");
+
 	int fd = openat(
 		logDir, path,
 		O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC,
logsubject'>Remove wiki scriptJune McEnroe Wikipedia seems to have removed the one-sentence extracts from the opensearch results. Too bad. It's not a wiki script, what we need is a command that fetches single-sentence summaries of articles on Wikipedia. 2020-02-19Add The Obelisk GateJune McEnroe 2020-02-17Add Four Tet — HandsJune McEnroe One from the cafe that caught my attention. 2020-02-12Simplify macOS notify-sendJune McEnroe 2020-02-12Add imbox and notemap to pageJune McEnroe 2020-02-12Collapse simple linksJune McEnroe 2020-02-12Move catgirl up the pageJune McEnroe 2020-02-12Update catgirl pty grabJune McEnroe 2020-02-12Link to cgit /about pages where appropriateJune McEnroe 2020-02-11Separate LINKS from BINS for html to workJune McEnroe 2020-02-11Add margin to Bl-bullet itemsJune McEnroe 2020-02-10Match URLs inside parens or with paired parens insideJune McEnroe 2020-02-10Duplicate effective URL before passing it back to curlJune McEnroe Apparently sometimes it didn't like receiving its own internal storage to parse again. Understandable. 2020-02-09Add To Be Taught, If FortunateJune McEnroe 2020-02-04Add The Future of Another TimelineJune McEnroe Wow. One of the best I've read. 2020-01-31Reorganize the Makefile for the umpteenth timeJune McEnroe Broke out LDLIBS for each bin, and made everything more uniform. 2020-01-28Change scout sensitivity to 1.4June McEnroe idk it seems to work. 2020-01-28Import shows.txtJune McEnroe