mirror of
https://github.com/cathugger/mkp224o.git
synced 2025-01-25 02:02:57 -03:00
close filter files, more error handling
This commit is contained in:
parent
e933a9b806
commit
a3e141e79b
2 changed files with 11 additions and 5 deletions
|
@ -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;
|
||||
}
|
||||
|
|
6
main.c
6
main.c
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
@ -258,11 +259,8 @@ int main(int argc,char **argv)
|
|||
}
|
||||
else if (*arg == 'f') {
|
||||
if (argc--) {
|
||||
const char *filename = *argv++;
|
||||
if (!loadfilterfile(filename)) {
|
||||
fprintf(stderr,"failed to load filter file %s\n",filename);
|
||||
if (!loadfilterfile(*argv++))
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
else
|
||||
e_additional();
|
||||
|
|
Loading…
Add table
Reference in a new issue