I tried to compile the downloader for both Windows and Linux and it worked every time. Has anyone an explanation for this? Here's my code (in C):
Code: Select all
#include <stdlib.h>
#include <errno.h>
#include <curl/curl.h>
#include <switch.h>
size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
size_t written = fwrite(ptr, size, nmemb, stream);
return written;
}
int downloadFile(char* url, char* output){
CURL *curl;
FILE *fp;
CURLcode res;
curl = curl_easy_init();
if (curl) {
fp = fopen(output,"wb");
if (fp==NULL){
printf("Failed opening file, abort...\n");
return 1;
}
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
fclose(fp);
if (res!= CURLE_OK){
printf("Error: %s\n", curl_easy_strerror(res));
return 1;
}
}
return 0;
}