summaryrefslogtreecommitdiff
path: root/download.c
diff options
context:
space:
mode:
authorNick White <arch@njw.me.uk>2007-03-07 01:25:23 +0000
committerNick White <arch@njw.me.uk>2007-03-07 01:25:23 +0000
commit49472a3a8ff731dcccd8099c4070119426c49145 (patch)
tree2f50580a790ddcfddbd1329727c95caf354a295b /download.c
parent38d38ea919c6a2e3faeaee0b036607259f7a428c (diff)
various checks & cleanups, default usage, hook script
Add file valid checks to update Add file checks to parse contents Remove empty files which don't download Automatically attempt to update contents if they cannot be opened Add default showopts if no options are passed Remove show struct mention in usage Move order of usage Add alternative media toc file option Added commit hook script git-archimport-id: getht@sv.gnu.org/getht--mainline--0.1--patch-6
Diffstat (limited to 'download.c')
-rw-r--r--download.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/download.c b/download.c
index 099a65f..6e83afb 100644
--- a/download.c
+++ b/download.c
@@ -44,7 +44,7 @@ extern char proxy_user[STR_MAX];
extern char proxy_pass[STR_MAX];
extern CURL *main_curl_handle;
-void save_file(CURL *curl_handle, char *url, char *filepath)
+int save_file(CURL *curl_handle, char *url, char *filepath)
/* Save the file *url to *filepath */
{
printf("Downloading %s\n",url);
@@ -55,7 +55,10 @@ void save_file(CURL *curl_handle, char *url, char *filepath)
if(curl_handle) {
FILE *file;
if((file = fopen(filepath,"w")) == NULL)
+ {
fprintf(stderr,"Error: cannot open file %s for writing.\n",filepath);
+ return 1;
+ }
curl_easy_setopt(curl_handle, CURLOPT_URL, url);
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_func);
@@ -98,7 +101,11 @@ void save_file(CURL *curl_handle, char *url, char *filepath)
curl_easy_setopt(curl_handle, CURLOPT_PROGRESSFUNCTION, update_progress);
if(curl_easy_perform(curl_handle))
+ {
+ remove(filepath);
fprintf(stderr,"Error, could not download %s\n",url);
+ return 1;
+ }
/* double d;
curl_easy_getinfo(curl_handle, CURLINFO_SIZE_DOWNLOAD, &d);
@@ -117,7 +124,9 @@ void save_file(CURL *curl_handle, char *url, char *filepath)
else {
fprintf(stderr,"Error: curl failed to initialise.\n");
printf("Could not download %s\n",url);
+ return 1;
}
+ return 0;
}
int update_progress(void *data, double dltotal, double dlnow,