]> git.ipfire.org Git - thirdparty/git.git/commitdiff
http: fix build error on FreeBSD
authorPatrick Steinhardt <ps@pks.im>
Wed, 16 Oct 2024 08:13:18 +0000 (10:13 +0200)
committerTaylor Blau <me@ttaylorr.com>
Wed, 16 Oct 2024 21:00:49 +0000 (17:00 -0400)
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>
http.c

diff --git a/http.c b/http.c
index d59e59f66b12b62e187f4a9bbacfca2d31d658f9..72973175a85e31fe200e0f2fea73678e22a887da 100644 (file)
--- a/http.c
+++ b/http.c
@@ -2290,17 +2290,19 @@ static int http_request_reauth(const char *url,
                case HTTP_REQUEST_STRBUF:
                        strbuf_reset(result);
                        break;
-               case HTTP_REQUEST_FILE:
-                       if (fflush(result)) {
+               case HTTP_REQUEST_FILE: {
+                       FILE *f = result;
+                       if (fflush(f)) {
                                error_errno("unable to flush a file");
                                return HTTP_START_FAILED;
                        }
-                       rewind(result);
-                       if (ftruncate(fileno(result), 0) < 0) {
+                       rewind(f);
+                       if (ftruncate(fileno(f), 0) < 0) {
                                error_errno("unable to truncate a file");
                                return HTTP_START_FAILED;
                        }
                        break;
+               }
                default:
                        BUG("Unknown http_request target");
                }