mirror of
https://github.com/cathugger/mkp224o.git
synced 2025-04-23 15:29:11 +00: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];
|
char buf[128];
|
||||||
FILE *f = fopen(fname,"r");
|
FILE *f = fopen(fname,"r");
|
||||||
if (!f)
|
if (!f) {
|
||||||
|
fprintf(stderr,"failed to load filter file \"%s\": %s\n",fname,strerror(errno));
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
while (fgets(buf,sizeof(buf),f)) {
|
while (fgets(buf,sizeof(buf),f)) {
|
||||||
for (char *p = buf;*p;++p) {
|
for (char *p = buf;*p;++p) {
|
||||||
if (*p == '\n') {
|
if (*p == '\n') {
|
||||||
|
@ -512,5 +514,11 @@ static bool loadfilterfile(const char *fname)
|
||||||
if (*buf && *buf != '#' && memcmp(buf,"//",2) != 0)
|
if (*buf && *buf != '#' && memcmp(buf,"//",2) != 0)
|
||||||
filters_add(buf);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
6
main.c
6
main.c
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -258,11 +259,8 @@ int main(int argc,char **argv)
|
||||||
}
|
}
|
||||||
else if (*arg == 'f') {
|
else if (*arg == 'f') {
|
||||||
if (argc--) {
|
if (argc--) {
|
||||||
const char *filename = *argv++;
|
if (!loadfilterfile(*argv++))
|
||||||
if (!loadfilterfile(filename)) {
|
|
||||||
fprintf(stderr,"failed to load filter file %s\n",filename);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
e_additional();
|
e_additional();
|
||||||
|
|
Loading…
Add table
Reference in a new issue