Copy tmp file to hosts file when complete
parent
1c6d230aac
commit
d2d092ed31
26
src/rhosts.c
26
src/rhosts.c
|
|
@ -27,6 +27,11 @@ int main(int argc, char *argv[]){
|
|||
printf("%d - download_entries failed",rc);
|
||||
return rc;
|
||||
}
|
||||
rc = copy_tmp_to_hosts();
|
||||
if (rc != 0){
|
||||
printf("%d - failed to copy to hosts file",rc);
|
||||
return rc;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -333,3 +338,24 @@ int copy_old_download(char *url){
|
|||
fclose(tmpf);
|
||||
return 0;
|
||||
}
|
||||
// Copies the contents of the temp file to the hosts file
|
||||
int copy_tmp_to_hosts(){
|
||||
FILE *tmpf;
|
||||
tmpf = fopen(TMPLOCATION,"r");
|
||||
if (tmpf == NULL)
|
||||
return 1;
|
||||
FILE *hostsf;
|
||||
hostsf = fopen(HOSTSLOCATION, "w");
|
||||
if (hostsf == NULL){
|
||||
printf("Failed to open %s\n",HOSTSLOCATION);
|
||||
fclose(tmpf);
|
||||
return 1;
|
||||
}
|
||||
char c;
|
||||
|
||||
for(c = fgetc(tmpf);c != EOF;c = fgetc(tmpf)){
|
||||
fputc(c,hostsf);
|
||||
}
|
||||
remove(TMPLOCATION);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,4 +46,5 @@ int add_site_entries(struct entry **entries);
|
|||
int download_libcurl(char *e);
|
||||
int parse_download(char *buff, size_t size, size_t nmemb);
|
||||
int copy_old_download(char *url);
|
||||
int copy_tmp_to_hosts();
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue