aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-09-07 16:01:37 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-09-07 16:01:37 +0200
commit6c7faa7f9063aca15345c9aeb95d651a5fe983f9 (patch)
tree6a24cc498535126824bd7a347ae2d3026b4568c4
parentf9e3516f5026babdea65e4cb6bb3756f0f8dd25a (diff)
downloadlibweb-6c7faa7f9063aca15345c9aeb95d651a5fe983f9.tar.gz
http.c: Use BUFSIZ instead of arbitrary value
According to C99 7.19.1p3: BUFSIZ is a macro that expands to an integer constant expression that is the size of the buffer used by the setbuf function. In other words, this means BUFSIZ is the most optimal length for a buffer that reads a file into memory in chunks using fread(3). Note: the number of bytes sent to the client might be less than BUFSIZ, so this would act as a bottleneck, no matter how large the buffer passed to fread(3) is.
-rw-r--r--http.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/http.c b/http.c
index 1ecdb19..13790b8 100644
--- a/http.c
+++ b/http.c
@@ -644,7 +644,7 @@ static int write_body_file(struct http_ctx *const h, bool *const close)
struct write_ctx *const w = &h->wctx;
const struct http_response *const r = &w->r;
const unsigned long long left = r->n - w->n;
- char buf[1024];
+ char buf[BUFSIZ];
const size_t rem = left > sizeof buf ? sizeof buf : left;
if (!fread(buf, 1, rem, r->f))