Fix xsendfile properly. - geomyidae - A small C-based gopherd.
(HTM) git clone git://bitreich.org/geomyidae/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/geomyidae/
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Tags
(DIR) README
(DIR) LICENSE
---
(DIR) commit 429ea45adba32c7ffa87b8b00528e26edc701e74
(DIR) parent a2eaebc870ac0a24f35beef0bf8ffa786d5933a3
(HTM) Author: Christoph Lohmann <20h@r-36.net>
Date: Sun, 7 Jun 2020 21:39:30 +0200
Fix xsendfile properly.
Diffstat:
M ind.c | 24 ++++++++++--------------
1 file changed, 10 insertions(+), 14 deletions(-)
---
(DIR) diff --git a/ind.c b/ind.c
@@ -119,23 +119,19 @@ xsendfile(int fd, int sock)
count = st.st_size;
}
- if (count == 0) {
- sendb = xmalloc(bufsiz);
- while ((len = read(fd, sendb, bufsiz)) > 0) {
- sendi = sendb;
- while (len > 0) {
- if ((sent = send(sock, sendi, len, 0)) < 0) {
- free(sendb);
- return -1;
- }
- len -= sent;
- sendi += sent;
+ sendb = xmalloc(bufsiz);
+ while ((len = read(fd, sendb, bufsiz)) > 0) {
+ sendi = sendb;
+ while (len > 0) {
+ if ((sent = send(sock, sendi, len, 0)) < 0) {
+ free(sendb);
+ return -1;
}
+ len -= sent;
+ sendi += sent;
}
- free(sendb);
- return 0;
}
-
+ free(sendb);
return 0;
}