MAINTAINERS: Add Peter Xu and myself as co-maintainer of "Memory API"
[qemu.git] / contrib / elf2dmp / download.c
blobd09e607431fc5a7a5f3094091d0e26c9aae5f649
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 int download_url(const char *name, const char *url)
14 int err = 0;
15 FILE *file;
16 CURL *curl = curl_easy_init();
18 if (!curl) {
19 return 1;
22 file = fopen(name, "wb");
23 if (!file) {
24 err = 1;
25 goto out_curl;
28 curl_easy_setopt(curl, CURLOPT_URL, url);
29 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
30 curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);
31 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
32 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
34 if (curl_easy_perform(curl) != CURLE_OK) {
35 err = 1;
36 fclose(file);
37 unlink(name);
38 goto out_curl;
41 err = fclose(file);
43 out_curl:
44 curl_easy_cleanup(curl);
46 return err;