http: fix build error on FreeBSD

The `result` parameter passed to `http_request_reauth()` may either point to a `struct strbuf` or a `FILE *`, where the `target` parameter tells us which of either it actually is. To accommodate for both types the pointer is a `void *`, which we then pass directly to functions without doing a cast. This is fine on most platforms, but it breaks on FreeBSD because `fileno()` is implemented as a macro that tries to directly access the `FILE *` structure. Fix this issue by storing the `FILE *` in a local variable before we pass it on to other functions. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Taylor Blau <me@ttaylorr.com>

Patrick Steinhardt committed Oct 16, 2024 at 10:13 UTC 80ebd91b83d50008f1dc9027bc5aee6d375c70f3
1 file changed +6 -4
http.c
+6 -4
@@ -2290,17 +2290,19 @@ static int http_request_reauth(const char *url,
2290 case HTTP_REQUEST_STRBUF:
2291 strbuf_reset(result);
2292 break;
2293 - case HTTP_REQUEST_FILE:
2294 - if (fflush(result)) {
2293 + case HTTP_REQUEST_FILE: {
2294 + FILE *f = result;
2295 + if (fflush(f)) {
2296 error_errno("unable to flush a file");
2297 return HTTP_START_FAILED;
2298 }
2298 - rewind(result);
2299 - if (ftruncate(fileno(result), 0) < 0) {
2299 + rewind(f);
2300 + if (ftruncate(fileno(f), 0) < 0) {
2301 error_errno("unable to truncate a file");
2302 return HTTP_START_FAILED;
2303 }
2304 break;
2305 + }
2306 default:
2307 BUG("Unknown http_request target");
2308 }