diff options
author | June McEnroe <june@causal.agency> | 2020-11-28 21:10:25 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-11-28 21:46:28 -0500 |
commit | d9e8a44f6f56393e4b08b4570115de77cf0d2a2f (patch) | |
tree | 16fdcf907fba001844e7eb7fa49db21856fff9c4 /concat.c | |
parent | Refactor IMAP struct (diff) | |
download | bubger-d9e8a44f6f56393e4b08b4570115de77cf0d2a2f.tar.gz bubger-d9e8a44f6f56393e4b08b4570115de77cf0d2a2f.zip |
Replace templateBuffer with templateString
Diffstat (limited to '')
-rw-r--r-- | concat.c | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/concat.c b/concat.c index 3e0dec6..c59a828 100644 --- a/concat.c +++ b/concat.c @@ -27,7 +27,6 @@ #include <err.h> #include <inttypes.h> -#include <limits.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> @@ -82,8 +81,7 @@ void concatData( errx(EX_TEMPFAIL, "no thread with root UID %" PRIu32, uid); } -static const char *uidPath(uint32_t uid, const char *type) { - static char buf[PATH_MAX]; +static char *uidPath(uint32_t uid, const char *type) { char str[32]; snprintf(str, sizeof(str), "%" PRIu32, uid); struct Variable vars[] = { @@ -91,18 +89,18 @@ static const char *uidPath(uint32_t uid, const char *type) { { "type", type }, {0}, }; - templateBuffer(buf, sizeof(buf), PATH_UID, vars, escapePath); - return buf; + return templateString(PATH_UID, vars, escapePath); } static time_t uidNewest(struct List uids, const char *type) { time_t newest = 0; for (size_t i = 0; i < uids.len; ++i) { - const char *path = uidPath(dataCheck(uids.ptr[i], Number).number, type); + char *path = uidPath(dataCheck(uids.ptr[i], Number).number, type); struct stat status; int error = stat(path, &status); if (error) err(EX_DATAERR, "%s", path); if (status.st_mtime > newest) newest = status.st_mtime; + free(path); } return newest; } @@ -129,22 +127,22 @@ static int concatHTML(FILE *file, struct List thread) { || htmlSubthreadClose(file); } else { uint32_t uid = dataCheck(thread.ptr[i], Number).number; - error = concatFile(file, uidPath(uid, "html")); + char *path = uidPath(uid, "html"); + error = concatFile(file, path); + free(path); } if (error) return error; } return 0; } -static const char *threadPath(const char *messageID, const char *type) { - static char buf[PATH_MAX]; +static char *threadPath(const char *messageID, const char *type) { struct Variable vars[] = { { "messageID", messageID }, { "type", type }, {0}, }; - templateBuffer(buf, sizeof(buf), PATH_THREAD, vars, escapePath); - return buf; + return templateString(PATH_THREAD, vars, escapePath); } const char *concatHead; @@ -155,7 +153,7 @@ static void concatThread(struct List thread, const struct Envelope *envelope) { int error; FILE *file; - const char *path; + char *path; struct stat status; path = threadPath(envelope->messageID, "mbox"); @@ -166,13 +164,16 @@ static void concatThread(struct List thread, const struct Envelope *envelope) { for (size_t i = 0; i < flat.len; ++i) { uint32_t uid = dataCheck(flat.ptr[i], Number).number; - error = concatFile(file, uidPath(uid, "mbox")); + char *src = uidPath(uid, "mbox"); + error = concatFile(file, src); if (error) err(EX_IOERR, "%s", path); + free(src); } error = fclose(file); if (error) err(EX_IOERR, "%s", path); } + free(path); path = threadPath(envelope->messageID, "atom"); error = stat(path, &status); @@ -185,13 +186,16 @@ static void concatThread(struct List thread, const struct Envelope *envelope) { for (size_t i = 0; i < flat.len; ++i) { uint32_t uid = dataCheck(flat.ptr[i], Number).number; - error = concatFile(file, uidPath(uid, "atom")); + char *src = uidPath(uid, "atom"); + error = concatFile(file, src); if (error) err(EX_IOERR, "%s", path); + free(src); } error = atomThreadClose(file) || fclose(file); if (error) err(EX_IOERR, "%s", path); } + free(path); path = threadPath(envelope->messageID, "html"); error = stat(path, &status); @@ -214,6 +218,7 @@ static void concatThread(struct List thread, const struct Envelope *envelope) { || fclose(file); if (error) err(EX_IOERR, "%s", path); } + free(path); listFree(flat); } @@ -252,8 +257,10 @@ void concatIndex(struct List threads, const struct Envelope *envelopes) { listFlatten(&flat, threads); for (size_t i = flat.len - 1; i < flat.len; --i) { uint32_t uid = dataCheck(flat.ptr[i], Number).number; - error = concatFile(file, uidPath(uid, "atom")); + char *src = uidPath(uid, "atom"); + error = concatFile(file, src); if (error) err(EX_IOERR, "%s", path); + free(src); } listFree(flat); @@ -265,9 +272,10 @@ void concatIndex(struct List threads, const struct Envelope *envelopes) { for (size_t i = 0; i < threads.len; ++i) { struct stat status; - const char *path = threadPath(envelopes[i].messageID, "html"); + char *path = threadPath(envelopes[i].messageID, "html"); int error = stat(path, &status); if (error) err(EX_DATAERR, "%s", path); + free(path); order[i].index = i; order[i].created = envelopes[i].time; |