From 9b45bc23820e7f1cebccbd61788ed4118571f88d Mon Sep 17 00:00:00 2001 From: Justin Reichardt Date: Wed, 25 Aug 2021 21:28:02 -0500 Subject: [PATCH] Created preserve_static_entries() It opens hosts and a tmp file and then closes them --- src/rhosts.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/rhosts.c b/src/rhosts.c index 2070790..8dec537 100644 --- a/src/rhosts.c +++ b/src/rhosts.c @@ -18,6 +18,7 @@ int main(int argc, char *argv[]){ if (rc != 0){return rc;} parse_config(&entries); + rc = preserve_static_entries(); // Closing files before exiting @@ -123,3 +124,22 @@ short int determine_config_entry_value(char *buff){ else if (strcmp(buff,"download") == 0){return CONTENTTYPE_DOWNLOAD;} else {return CONTENTTYPE_ERROR;} } + +// Copies the beginning of the hosts file to tmpfile +int preserve_static_entries(){ + FILE *hostsf; + FILE *tmpf; + hostsf = fopen(HOSTSLOCATION, "r"); + if (hostsf == NULL){return 1;} + tmpf = fopen(TMPLOCATION,"w"); + if (tmpf == NULL){ + fclose(hostsf); + return 1; + } + + + + fclose(hostsf); + fclose(tmpf); + return 0; +}