Merge tag 'v9.0.0-rc3'
[qemu/ar7.git] / contrib / elf2dmp / download.c
blob21306b3fd4c44856f5686081f27e4323fd3ccb53
1 /*
2 * Copyright (c) 2018 Virtuozzo International GmbH
4 * This work is licensed under the terms of the GNU GPL, version 2 or later.
6 */
8 #include "qemu/osdep.h"
9 #include <curl/curl.h>
10 #include "download.h"
12 bool download_url(const char *name, const char *url)
14 bool success = false;
15 FILE *file;
16 CURL *curl = curl_easy_init();
18 if (!curl) {
19 return false;
22 file = fopen(name, "wb");
23 if (!file) {
24 goto out_curl;
27 if (curl_easy_setopt(curl, CURLOPT_URL, url) != CURLE_OK
28 || curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL) != CURLE_OK
29 || curl_easy_setopt(curl, CURLOPT_WRITEDATA, file) != CURLE_OK
30 || curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1) != CURLE_OK
31 || curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0) != CURLE_OK
32 || curl_easy_perform(curl) != CURLE_OK) {
33 unlink(name);
34 fclose(file);
35 } else {
36 success = !fclose(file);
39 out_curl:
40 curl_easy_cleanup(curl);
42 return success;