More refactorings, pretty much done!
This commit is contained in:
parent
31186418c3
commit
cb36f1790a
14
main.c
14
main.c
@ -31,8 +31,7 @@ static char *CONFIG;
|
|||||||
* @param mode whichever mode host file you want to open
|
* @param mode whichever mode host file you want to open
|
||||||
* @return FILE *
|
* @return FILE *
|
||||||
*/
|
*/
|
||||||
FILE *fopenHostsFile(char *mode)
|
FILE *fopenHostsFile(char *mode) {
|
||||||
{
|
|
||||||
return fopen(HOSTFILE, mode);
|
return fopen(HOSTFILE, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,13 +70,13 @@ void modifyHostsFile(char *oldhost, char *newhost, int deleteHost) {
|
|||||||
newHostsFile[strlen(newHostsFile)] = EOF;
|
newHostsFile[strlen(newHostsFile)] = EOF;
|
||||||
|
|
||||||
// // Seek to 0
|
// // Seek to 0
|
||||||
// fseek(hostsFile, 0, SEEK_SET);
|
fseek(hostsFile, 0, SEEK_SET);
|
||||||
fclose(hostsFile);
|
fclose(hostsFile);
|
||||||
|
|
||||||
// If this failed, write an error message to stderr
|
// If this failed, write an error message to stderr
|
||||||
// ONFAILED(0, (fwrite(newHostsFile, sizeof(char), sizeof(newHostsFile), hostsFile))) {
|
ONFAILED(0, (fwrite(newHostsFile, sizeof(char), sizeof(newHostsFile), hostsFile))) {
|
||||||
// fprintf(stderr, "Did not write anything!\n");
|
fprintf(stderr, "Did not write anything!\n");
|
||||||
// }
|
}
|
||||||
fprintf(stderr, "New hosts file: \n%s\n", newHostsFile);
|
fprintf(stderr, "New hosts file: \n%s\n", newHostsFile);
|
||||||
// fclose(hostsFile);
|
// fclose(hostsFile);
|
||||||
}
|
}
|
||||||
@ -86,8 +85,7 @@ void modifyHostsFile(char *oldhost, char *newhost, int deleteHost) {
|
|||||||
/**
|
/**
|
||||||
* Block a hosts using the hostsFile in FILE
|
* Block a hosts using the hostsFile in FILE
|
||||||
*/
|
*/
|
||||||
void blockHost(char *host)
|
void blockHost(char *host) {
|
||||||
{
|
|
||||||
FILE *hostsFile = fopenHostsFile("a");
|
FILE *hostsFile = fopenHostsFile("a");
|
||||||
char blockRule[256];
|
char blockRule[256];
|
||||||
sprintf(blockRule, "%s %s\n", blockString, host);
|
sprintf(blockRule, "%s %s\n", blockString, host);
|
||||||
|
Loading…
Reference in New Issue
Block a user