From 72b69f813efe5570d90b13507228704915542077 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Fri, 17 Apr 2020 16:46:14 -0400 Subject: Factor out templateBuffer --- archive.h | 4 ++++ template.c | 25 ++++++++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/archive.h b/archive.h index 06fd435..b1cb3dc 100644 --- a/archive.h +++ b/archive.h @@ -150,6 +150,10 @@ int templateRender( FILE *file, const char *template, const struct Variable vars[], EscapeFn *escape ); +char *templateBuffer( + char *buf, size_t cap, const char *template, + const struct Variable vars[], EscapeFn *escape +); char *templateURL(const char *template, const struct Variable vars[]); char *decodeHeader(const char *header); diff --git a/template.c b/template.c index 8653769..afb9173 100644 --- a/template.c +++ b/template.c @@ -103,19 +103,30 @@ int templateRender( return 0; } +char *templateBuffer( + char *buf, size_t cap, const char *template, + const struct Variable vars[], EscapeFn *escape +) { + FILE *file = fmemopen(buf, cap, "w"); + if (!file) err(EX_OSERR, "fmemopen"); + + int error = templateRender(file, template, vars, escape) + || fclose(file); + assert(!error); + + // XXX: fmemopen only null-terminates if there is room. + buf[cap - 1] = '\0'; + return buf; +} + char *templateURL(const char *template, const struct Variable vars[]) { size_t cap = strlen(template) + 1; for (const struct Variable *var = vars; var->name; ++var) { cap += 3 * strlen(var->value); } + char *buf = malloc(cap); if (!buf) err(EX_OSERR, "malloc"); - FILE *file = fmemopen(buf, cap, "w"); - if (!file) err(EX_OSERR, "fmemopen"); - - int error = templateRender(file, template, vars, escapeURL) - || fclose(file); - assert(!error); - return buf; + return templateBuffer(buf, cap, template, vars, escapeURL); } -- cgit 1.4.1 and)Author 2024-11-05Update to Linux man-pages 6.9.1Štěpán Němec 2024-11-05Update to Linux man-pages 6.9Štěpán Němec 2024-05-15Update to NetBSD 10.0 2066.5Štěpán Němec 2024-05-15Update to OpenBSD 7.5Štěpán Němec 2024-03-21Update to Linux man-pages 6.7 2065.7Štěpán Němec 2024-03-03Update to Linux man-pages 6.06 2065.06Štěpán Němec 2023-11-27Update to FreeBSD 14.0 2065.05Štěpán Němec 2023-10-16Update to OpenBSD 7.4 2064.25Kusoneko 2023-10-11Update to Linux man-pages 6.05 2064.15Štěpán Němec 2023-10-11Update to FreeBSD 13.2Štěpán Němec 2023-10-11Update to Linux man-pages 6.04, OpenBSD 7.3Štěpán Němec 2023-02-13Update to Linux man-pages 6.03 2063.93Štěpán Němec 2023-02-13Update to Linux man-pages 6.02Štěpán Němec 2022-11-01Update to Linux man-pages 6.01 2063.91Štěpán Němec 2022-10-21Update to OpenBSD 7.2 2063.9June McEnroe 2022-10-16NetBSD: include text.tar.xz man pages 2063.8Štěpán Němec 2022-10-16Update to Linux man-mages 6.00Štěpán Němec 2022-10-16Update to NetBSD 9.3Štěpán Němec 2022-09-18Make copyrights and AUTHORS consistentJune McEnroe 2022-07-27Update to FreeBSD 13.1 2062.83June McEnroe 2022-07-27openbsd: Include man pages from baseXX.tgzKeith Whitney 2022-05-08Update to OpenBSD 7.1 2062.73June McEnroe 2021-10-15Update to OpenBSD 7.0 2062.63June McEnroe 2021-08-29Update to Linux man-pages 5.13 2062.53Štěpán Němec 2021-08-26Update to NetBSD 9.2 2062.52June McEnroe 2021-08-26Support DESTDIR in install/uninstallJune McEnroe 2021-08-26Add version number generatorJune McEnroe 2021-08-22Add ISC license headerJune McEnroe 2021-08-22Update to Linux man-pages 5.12Štěpán Němec 2021-06-21Add manuals for macOS 11.3June McEnroe 2021-05-08Update to OpenBSD 6.9June McEnroe 2021-04-26Update to Linux man-pages 5.11June McEnroe 2021-04-26Update to FreeBSD 13.0June McEnroe 2021-01-27Completely rewrite how manuals are fetched and installedJune McEnroe 2020-12-14Update to man-pages-posix 2017-aJune McEnroe 2020-12-14Update to OpenBSD 6.8June McEnroe 2020-12-14Update to NetBSD 9.1June McEnroe 2020-12-14Update to man-pages 5.09June McEnroe 2020-12-14Update to FreeBSD 12.2June McEnroe 2020-06-08Update to OpenBSD 6.7June McEnroe 2020-05-04Add hack for macOS to search extra man sectionsJune McEnroe 2020-05-04Don't clear MANSECTJune McEnroe