cansniffer: simplify conditional cases
refactoring, reduce some levels of indention Signed-off-by: Lothar Rubusch <l.rubusch@gmail.com>pull/316/head
parent
93a6cd6dfb
commit
8bf57429fc
25
cansniffer.c
25
cansniffer.c
|
|
@ -783,8 +783,11 @@ void writesettings(char* name)
|
|||
|
||||
strncat(fname, name, 29 - strlen(fname));
|
||||
fd = open(fname, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
|
||||
if (fd <= 0) {
|
||||
printf("unable to write setting file '%s'!\n", fname);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fd > 0) {
|
||||
for (i = 0; i < idx ;i++) {
|
||||
sprintf(buf, "<%08X>%c.", sniftab[i].current.can_id, (is_set(i, ENABLE))?'1':'0');
|
||||
if (write(fd, buf, 12) < 0)
|
||||
|
|
@ -800,9 +803,6 @@ void writesettings(char* name)
|
|||
}
|
||||
close(fd);
|
||||
}
|
||||
else
|
||||
printf("unable to write setting file '%s'!\n", fname);
|
||||
}
|
||||
|
||||
int readsettings(char* name)
|
||||
{
|
||||
|
|
@ -815,10 +815,15 @@ int readsettings(char* name)
|
|||
strncat(fname, name, 29 - strlen(fname));
|
||||
fd = open(fname, O_RDONLY);
|
||||
|
||||
if (fd > 0) {
|
||||
if (fd <= 0) {
|
||||
return -1;
|
||||
}
|
||||
idx = 0;
|
||||
while (!done) {
|
||||
if (read(fd, &buf, 29) == 29) {
|
||||
if (read(fd, &buf, 29) != 29) {
|
||||
done = true;
|
||||
continue;
|
||||
}
|
||||
unsigned long id = strtoul(&buf[1], (char **)NULL, 16);
|
||||
|
||||
sniftab[idx].current.can_id = id;
|
||||
|
|
@ -836,15 +841,9 @@ int readsettings(char* name)
|
|||
|
||||
if (++idx >= MAX_SLOTS)
|
||||
break;
|
||||
}
|
||||
else
|
||||
done = true;
|
||||
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue