const struct location *loc = erec->locations, *iloc;
const struct input_descriptor *indesc = loc->indesc, *tmp;
const char *line = NULL; /* silence gcc */
- char buf[1024];
+ char buf[1024] = {};
char *pbuf = NULL;
unsigned int i, end;
int l, ret;
*strchrnul(line, '\n') = '\0';
break;
case INDESC_FILE:
- memset(buf, 0, sizeof(buf));
- orig_offset = lseek(indesc->fd, 0, SEEK_CUR);
- lseek(indesc->fd, loc->line_offset, SEEK_SET);
- ret = read(indesc->fd, buf, sizeof(buf) - 1);
+ orig_offset = ftell(indesc->fp);
+ fseek(indesc->fp, loc->line_offset, SEEK_SET);
+ ret = fread(buf, 1, sizeof(buf) - 1, indesc->fp);
if (ret > 0)
*strchrnul(buf, '\n') = '\0';
line = buf;
- lseek(indesc->fd, orig_offset, SEEK_SET);
+ fseek(indesc->fp, orig_offset, SEEK_SET);
break;
case INDESC_INTERNAL:
case INDESC_NETLINK:
if (nft_run(&nft, nf_sock, scanner, &state, &msgs) != 0)
rc = NFT_EXIT_FAILURE;
out:
- scanner_destroy(scanner);
erec_print_list(stderr, &msgs, nft.debug_mask);
+ scanner_destroy(scanner);
xfree(buf);
cache_release(&nft.cache);
iface_cache_release();
state->indesc->location = *loc;
state->indesc->type = INDESC_FILE;
state->indesc->name = xstrdup(filename);
- state->indesc->fd = fileno(f);
+ state->indesc->fp = f;
init_pos(state);
return NULL;
}
if (inpdesc && inpdesc->name) {
xfree(inpdesc->name);
inpdesc->name = NULL;
+ fclose(inpdesc->fp);
}
yypop_buffer_state(scanner);
} while (state->indesc_idx--);