commit afab58cb64f205ce9f469a328a7477b808b0c76c
parent fc6d4a6f69e305627d06955da27b8e8c4c5af6e0
Author: Eyal Sawady <ecs@d2evs.net>
Date: Wed, 21 Oct 2020 10:15:07 -0400
Fix plaintext display
Diffstat:
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/src/gmnlm.c b/src/gmnlm.c
@@ -908,10 +908,21 @@ display_plaintext(struct browser *browser, struct gemini_response *resp)
ioctl(fileno(browser->tty), TIOCGWINSZ, &ws);
char buf[BUFSIZ];
- int n;
- while ((n = BIO_read(resp->bio, buf, sizeof(buf)) != 0)) {
- while (n) {
- n -= fwrite(buf, 1, n, browser->tty);
+ for (int n = 1; n > 0;) {
+ n = BIO_read(resp->bio, buf, BUFSIZ);
+ if (n == -1) {
+ fprintf(stderr, "Error: read\n");
+ return 1;
+ }
+ ssize_t w = 0;
+ while (w < (ssize_t)n) {
+ ssize_t x = fwrite(&buf[w], 1, n - w, browser->tty);
+ if (ferror(browser->tty)) {
+ fprintf(stderr, "Error: write: %s\n",
+ strerror(errno));
+ return 1;
+ }
+ w += x;
}
}