Copy tmp file to hosts file when complete

stable
Justin Reichardt 2021-08-26 19:17:57 -05:00
parent 1c6d230aac
commit d2d092ed31
2 changed files with 27 additions and 0 deletions

View File

@ -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;
}

View File

@ -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