From ccb0e90d3b788db0d308b48f3f74b53928fe0395 Mon Sep 17 00:00:00 2001 From: Jacob Date: Thu, 16 Jan 2020 14:30:30 -0500 Subject: [PATCH] Delete/replace/add hosts within config reading loop. --- main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 0422994..47dd306 100644 --- a/main.c +++ b/main.c @@ -63,6 +63,10 @@ void blockHost(char *host) fclose(hostsFile); } +void deleteHost(char *host) +{ + +} void showHosts() { @@ -111,16 +115,18 @@ int update_hosts_file() { return 0; } } + replacehost(ptr->data, buf); strcpy(ptr->data, buf); prev = ptr; ptr = ptr->next; } else { + blockHost(buf); linkedlist_add(&hosts, buf); } } // In this case, the list got chopped off, we need to reset pointers and free the rest of our list. - if (ptr != NULL) { + if (ptr != NULL && prev != NULL) { prev->next = NULL; } @@ -129,6 +135,7 @@ int update_hosts_file() { while (ptr != NULL) { prev = ptr; ptr = ptr->next; + deleteHost(prev->data); free(prev->data); free(prev); }