Update include_file() to return FILE *. Signed-off-by: Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx> --- src/scanner.l | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/scanner.l b/src/scanner.l index ecf2354e3c2f..fe70df5c18ec 100644 --- a/src/scanner.l +++ b/src/scanner.l @@ -714,8 +714,8 @@ static void scanner_push_file(struct nft_ctx *nft, void *scanner, scanner_push_indesc(state, indesc); } -static int include_file(struct nft_ctx *nft, void *scanner, - const char *filename, const struct location *loc) +static FILE *include_file(struct nft_ctx *nft, void *scanner, + const char *filename, const struct location *loc) { struct parser_state *state = yyget_extra(scanner); struct error_record *erec; @@ -733,11 +733,11 @@ static int include_file(struct nft_ctx *nft, void *scanner, filename, strerror(errno)); goto err; } - scanner_push_file(nft, scanner, f, filename, loc); - return 0; + + return f; err: erec_queue(erec, state->msgs); - return -1; + return NULL; } static int include_glob(struct nft_ctx *nft, void *scanner, const char *pattern, @@ -749,6 +749,7 @@ static int include_glob(struct nft_ctx *nft, void *scanner, const char *pattern, glob_t glob_data; unsigned int i; int flags = 0; + FILE *f; int ret; char *p; @@ -804,9 +805,11 @@ static int include_glob(struct nft_ctx *nft, void *scanner, const char *pattern, if (len == 0 || path[len - 1] == '/') continue; - ret = include_file(nft, scanner, path, loc); - if (ret != 0) + f = include_file(nft, scanner, path, loc); + if (!f) goto err; + + scanner_push_file(nft, scanner, f, path, loc); } globfree(&glob_data); @@ -841,7 +844,14 @@ err: int scanner_read_file(struct nft_ctx *nft, const char *filename, const struct location *loc) { - return include_file(nft, nft->scanner, filename, loc); + FILE *f; + + f = include_file(nft, nft->scanner, filename, loc); + if (!f) + return -1; + + scanner_push_file(nft, nft->scanner, f, filename, loc); + return 0; } static bool search_in_include_path(const char *filename) -- 2.11.0