cgmnlm

Unnamed repository; edit this file 'description' to name the repository.
git clone git://code.clttr.info/cgmnlm.git
Log | Files | Refs | README | LICENSE

commit 6029d6a8464d26d0b9e314dc1beecca799df8d6a
parent 0fa1fb5d31c69cfb9d2cb3999d835cb7282e30a7
Author: René Wagner <rwagner@rw-net.de>
Date:   Thu, 28 Oct 2021 22:09:46 +0200

fix downloading of files

due to the wrong handling in download_resp() files may get
broken (last chunk missing) and file descriptors have not
been closed correctly.

Additionally we now allow downloading of local ressources
as well - for what its worth.

Diffstat:
Msrc/util.c | 12++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/util.c b/src/util.c @@ -9,6 +9,7 @@ #include <stdlib.h> #include <string.h> #include <sys/stat.h> +#include <unistd.h> #include "util.h" void @@ -83,10 +84,13 @@ download_resp(FILE *out, struct gemini_response resp, const char *path, fprintf(out, "Downloading %s to %s\n", url, path); char buf[BUFSIZ]; for (int n = 1; n > 0;) { - n = br_sslio_read(&resp.body, buf, sizeof(buf)); - if (n == -1) { - fprintf(stderr, "Error: read\n"); - return 1; + if (resp.sc) { + n = br_sslio_read(&resp.body, buf, BUFSIZ); + } else { + n = read(resp.fd, buf, BUFSIZ); + } + if (n < 0) { + break; } ssize_t w = 0; while (w < (ssize_t)n) {