saait

Simple static page generator
git clone https://git.sinitax.com/codemadness/saait
Log | Files | Refs | README | LICENSE | Upstream | sfeed.txt

commit 5ab8b2c66ca6181db6b7b9af602355bc917cca37
parent 534f2fd002afd451006265e7630ea1f052bd1db6
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Fri, 25 Nov 2016 16:48:10 +0100

optimization: dont allocate, just temporary NUL terminate

Diffstat:
Msaait.c | 21+++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/saait.c b/saait.c @@ -469,15 +469,11 @@ void writepage(FILE *fp, const char *filename, struct config *c, char *s) { struct variable *var, *v; - char *key, escape, *e, *value; - size_t keylen, line = 0; - int op; - - char *tmp; /* TODO */ - /* TODO */ - time_t t = 0; struct tm tm; - char outtime[256]; + time_t t; + int op, tmp; + char *key, escape, *e, *value, outtime[256]; + size_t keylen, line = 0; for (; *s; s++) { /* TODO: error if unterminated */ @@ -544,14 +540,15 @@ writepage(FILE *fp, const char *filename, struct config *c, char *s) ; parsetime(v->value, &t, &tm, NULL); + /* temporary NUL terminate */ + tmp = *e; + *e = '\0'; - /* TODO: check */ - tmp = estrndup(s, e - s); - if (!strftime(outtime, sizeof(outtime), tmp, &tm)) { + if (!strftime(outtime, sizeof(outtime), s, &tm)) { fprintf(stderr, "strftime: %s\n", strerror(errno)); exit(1); } - free(tmp); + *e = tmp; value = outtime; s = e;