commit ee6fe47e44bfb40cd92d6668e85fd893df3a12b8
parent 4bc55aaa138171db365377db0624c3ce0d878257
Author: Drew DeVault <sir@cmpwn.com>
Date: Sun, 20 Sep 2020 14:18:26 -0400
Correct trailing line feed detection
Diffstat:
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/gmnic.c b/src/gmnic.c
@@ -171,13 +171,15 @@ main(int argc, char *argv[])
if (resp.status / 10 != 2) {
break;
}
+ char last;
char buf[BUFSIZ];
- int n;
- for (n = 1; n > 0;) {
+ for (int n = 1; n > 0;) {
n = BIO_read(resp.bio, buf, BUFSIZ);
if (n == -1) {
fprintf(stderr, "Error: read\n");
return 1;
+ } else if (n != 0) {
+ last = buf[n - 1];
}
ssize_t w = 0;
while (w < (ssize_t)n) {
@@ -191,8 +193,7 @@ main(int argc, char *argv[])
}
}
if (strncmp(resp.meta, "text/", 5) == 0
- && linefeed
- && buf[n - 1] != '\n') {
+ && linefeed && last != '\n') {
printf("\n");
}
break;
@@ -202,7 +203,6 @@ next:
gemini_response_finish(&resp);
}
- (void)input_mode;
free(url);
return ret;
}