Skip to content

Commit 80ebd91

Browse files
pks-tttaylorr
authored andcommitted
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 <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent 87ad2a9 commit 80ebd91

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

http.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,17 +2290,19 @@ static int http_request_reauth(const char *url,
22902290
case HTTP_REQUEST_STRBUF:
22912291
strbuf_reset(result);
22922292
break;
2293-
case HTTP_REQUEST_FILE:
2294-
if (fflush(result)) {
2293+
case HTTP_REQUEST_FILE: {
2294+
FILE *f = result;
2295+
if (fflush(f)) {
22952296
error_errno("unable to flush a file");
22962297
return HTTP_START_FAILED;
22972298
}
2298-
rewind(result);
2299-
if (ftruncate(fileno(result), 0) < 0) {
2299+
rewind(f);
2300+
if (ftruncate(fileno(f), 0) < 0) {
23002301
error_errno("unable to truncate a file");
23012302
return HTTP_START_FAILED;
23022303
}
23032304
break;
2305+
}
23042306
default:
23052307
BUG("Unknown http_request target");
23062308
}

0 commit comments

Comments
 (0)