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.
This commit is contained in:
Yamagi Burmeister 2019-01-03 17:32:49 +01:00
parent 2199b67a39
commit ec6e0ee392

View file

@ -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
{