]> git.ipfire.org Git - people/ric9/pakfire.git/commitdiff
parser: Refactor reading from file
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 11 Jan 2025 13:23:04 +0000 (13:23 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 11 Jan 2025 13:23:04 +0000 (13:23 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/parser.c

index e915ff2b07d3773d27a3616e35406d3fe93f33a5..85eeedba20b3023ef36d792ea0b7b4b85b524009 100644 (file)
@@ -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;
 }