From 6c7faa7f9063aca15345c9aeb95d651a5fe983f9 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Thu, 7 Sep 2023 16:01:37 +0200 Subject: 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. --- http.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)) -- cgit v1.2.3