From 9e5f58c39ea510da6cffb7b23951b4ce25685d87 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 11 Jan 2025 13:23:04 +0000 Subject: [PATCH] parser: Refactor reading from file Signed-off-by: Michael Tremer --- src/pakfire/parser.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/pakfire/parser.c b/src/pakfire/parser.c index e915ff2b0..85eeedba2 100644 --- a/src/pakfire/parser.c +++ b/src/pakfire/parser.c @@ -947,14 +947,22 @@ ERROR: int pakfire_parser_read_file(struct pakfire_parser* parser, const char* path, struct pakfire_parser_error** error) { + FILE* f = NULL; + int r; + DEBUG(parser->ctx, "Parsing %s...\n", path); - FILE* f = fopen(path, "r"); + // Open the file + f = fopen(path, "r"); if (!f) - return 1; + return -errno; + + // Run the parser + r = pakfire_parser_read(parser, f, error); - int r = pakfire_parser_read(parser, f, error); - fclose(f); + // Close the file + if (f) + fclose(f); return r; } -- 2.47.3