fprintf(stdout,"curl returned %s; Downloaded %s \n",curl_easy_strerror(res),filepath);
fclose(file);
curl_easy_cleanup(curl);
return0;
fprintf(stdout,"curl returned %s; Downloaded %s \n",curl_easy_strerror(res),filepath);
}
char*
get_default_filepath(char*url)
{
char*url_copy=malloc(strlen(url)+1);
if(!url_copy){
die("Malloc failed!");
}
strcpy(url_copy,url);
char*get_default_filepath(char*url){
char*filepath=strdup(url);
char*filepath=url_copy;
char*tmp=strtok(filepath,"/");
while(tmp!=NULL){
while(tmp!=NULL){
filepath=tmp;
tmp=strtok(NULL,"/");
}
//TODO: move malloc and free from here
returnfilepath;
}
void
usage(){
puts("usage: <url> <file path>(optional, default is ./<filename on url>)");
usage()
{
puts("Usage:\n\t-u url to get file from, other arguments can be omited.\n\t-f filepath to save file to. Can be omited, filename from url will be used.\n\t-uf file with urls to fetch files from. \n\t-ff filepath file, file with paths to save files from urls file. Can be omited, filename from url will be used.\n\tTo perform at least one of -u arguments should be given.\nSupported combinations:\n\t<url>\n\t-u <url>\n\t-u <url> -f <path to save fileto>\n\t-uf <path to file with urls>\n\t-uf <path to file with url> -ff<path to file with filenames>\n!Program rewrites files!");