scribo

Email-based phlog generator
git clone git://git.z3bra.org/scribo.git
Log | Files | Refs

commit f03f0be08b98eb5096d147a398c8ffe2a0cd0c77
parent b87a87f72abf43c16c68ff9878b4612632222620
Author: Willy Goiffon <dev@z3bra.org>
Date:   Wed,  9 Sep 2020 22:43:08 +0200

Handle multiline base64 content

Diffstat:
Mscribo.c | 16+++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/scribo.c b/scribo.c @@ -215,22 +215,28 @@ write_8bit(FILE *in, FILE *out) int write_base64(FILE *in, FILE *out) { - size_t bufsiz; + size_t n, bufsiz; ssize_t len; - char *msg, *b64; + char *msg, *line, *b64; b64 = NULL; bufsiz = 0; - while ((len = getline(&b64, &bufsiz, in)) > 0); + line = NULL; + n = 0; + + while ((len = getline(&line, &n, in)) > 0) { + bufsiz += len; + b64 = realloc(b64, bufsiz); + strlcat(b64, line, bufsiz); + } len = base64_unfold(b64, bufsiz); len = base64_decode(&msg, (unsigned char *)b64, len); - free(b64); - fwrite(msg, 1, len, out); + free(b64); free(msg); return 0;