From: Michael Tremer Date: Sat, 11 Jan 2025 13:23:04 +0000 (+0000) Subject: parser: Refactor reading from file X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9e5f58c39ea510da6cffb7b23951b4ce25685d87;p=people%2Fric9%2Fpakfire.git parser: Refactor reading from file Signed-off-by: Michael Tremer --- 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; }