From ec6e0ee392f34faa1e74d0c499f95d04687af34c Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Thu, 3 Jan 2019 17:32:49 +0100 Subject: [PATCH] Provide a write callback to cURL. If we're passing file handles to libcurl to write the data into, the game may crash under Windows due to incompatible C runtimes between cURL and quake2. This is even mentioned in the official cURL doku. --- src/client/curl/download.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/client/curl/download.c b/src/client/curl/download.c index 44d5a414..30cd45f2 100644 --- a/src/client/curl/download.c +++ b/src/client/curl/download.c @@ -94,6 +94,12 @@ static size_t CL_HTTP_Recv(void *ptr, size_t size, size_t nmemb, void *stream) return bytes; } +static size_t CL_HTTP_CurlWriteCB(char* data, size_t size, size_t nmemb, void* userdata) +{ + dlhandle_t *dl = (dlhandle_t *)userdata; + return fwrite(data, size, nmemb, dl->file); +} + // -------- // Helper functions @@ -234,8 +240,8 @@ static void CL_StartHTTPDownload (dlqueue_t *entry, dlhandle_t *dl) if (dl->file) { - qcurl_easy_setopt(dl->curl, CURLOPT_WRITEDATA, dl->file); - qcurl_easy_setopt(dl->curl, CURLOPT_WRITEFUNCTION, NULL); + qcurl_easy_setopt(dl->curl, CURLOPT_WRITEDATA, dl); + qcurl_easy_setopt(dl->curl, CURLOPT_WRITEFUNCTION, CL_HTTP_CurlWriteCB); } else {