close filter files, more error handling

This commit is contained in:
cathugger
2020-05-22 22:30:14 +00:00
parent e933a9b806
commit a3e141e79b
2 changed files with 11 additions and 5 deletions

View File

@@ -500,8 +500,10 @@ static bool loadfilterfile(const char *fname)
{
char buf[128];
FILE *f = fopen(fname,"r");
if (!f)
if (!f) {
fprintf(stderr,"failed to load filter file \"%s\": %s\n",fname,strerror(errno));
return false;
}
while (fgets(buf,sizeof(buf),f)) {
for (char *p = buf;*p;++p) {
if (*p == '\n') {
@@ -512,5 +514,11 @@ static bool loadfilterfile(const char *fname)
if (*buf && *buf != '#' && memcmp(buf,"//",2) != 0)
filters_add(buf);
}
int fe = ferror(f);
fclose(f);
if (fe != 0) {
fprintf(stderr,"failure while reading filter file \"%s\": %s\n",fname,strerror(fe));
return false;
}
return true;
}