Otherwise this is becoming yet another callback hell...
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
        src/libpakfire/job.c \
        src/libpakfire/key.c \
        src/libpakfire/linter.c \
+       src/libpakfire/linter-file.c \
        src/libpakfire/log_buffer.c \
        src/libpakfire/log_stream.c \
        src/libpakfire/logging.c \
        src/libpakfire/include/pakfire/job.h \
        src/libpakfire/include/pakfire/key.h \
        src/libpakfire/include/pakfire/linter.h \
+       src/libpakfire/include/pakfire/linter-file.h \
        src/libpakfire/include/pakfire/log_buffer.h \
        src/libpakfire/include/pakfire/log_stream.h \
        src/libpakfire/include/pakfire/logging.h \
 
--- /dev/null
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2023 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#ifndef PAKFIRE_LINTER_FILE_H
+#define PAKFIRE_LINTER_FILE_H
+
+#ifdef PAKFIRE_PRIVATE
+
+struct pakfire_linter_file;
+
+#include <pakfire/ctx.h>
+#include <pakfire/file.h>
+#include <pakfire/linter.h>
+
+int pakfire_linter_file_create(struct pakfire_linter_file** lfile,
+       struct pakfire_ctx* ctx, struct pakfire_linter* linter, struct pakfire_file* file, int fd);
+
+struct pakfire_linter_file* pakfire_linter_file_ref(struct pakfire_linter_file* lfile);
+struct pakfire_linter_file* pakfire_linter_file_unref(struct pakfire_linter_file* lfile);
+
+#endif /* PAKFIRE_PRIVATE */
+#endif /* PAKFIRE_LINTER_FILE_H */
 
--- /dev/null
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2024 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#include <errno.h>
+#include <stdlib.h>
+
+#include <pakfire/ctx.h>
+#include <pakfire/file.h>
+#include <pakfire/linter.h>
+#include <pakfire/linter-file.h>
+
+struct pakfire_linter_file {
+       struct pakfire_ctx* ctx;
+       int nrefs;
+
+       // Linter
+       struct pakfire_linter* linter;
+
+       // File
+       struct pakfire_file* file;
+
+       // File Descriptor
+       int fd;
+};
+
+int pakfire_linter_file_create(struct pakfire_linter_file** lfile,
+               struct pakfire_ctx* ctx, struct pakfire_linter* linter, struct pakfire_file* file, int fd) {
+       struct pakfire_linter_file* l = NULL;
+       int r = 0;
+
+       // Check input
+       if (fd < 0)
+               return -EBADF;
+
+       // Allocate some memory
+       l = calloc(1, sizeof(*l));
+       if (!l)
+               return -errno;
+
+       // Store a reference to the context
+       l->ctx = pakfire_ctx_ref(ctx);
+
+       // Initialize the reference counter
+       l->nrefs = 1;
+
+       // Store a reference to the linter
+       l->linter = pakfire_linter_ref(linter);
+
+       // Store a reference to the file
+       l->file = pakfire_file_ref(file);
+
+       // Store the file descriptor
+       l->fd = dup(fd);
+       if (l->fd < 0) {
+               ERROR(l->ctx, "Could not duplicate file descriptor: %m\n");
+               r = -errno;
+               goto ERROR;
+       }
+
+       // Return the pointer
+       *lfile = pakfire_linter_file_ref(l);
+
+ERROR:
+       if (l)
+               pakfire_linter_file_unref(l);
+
+       return r;
+}
+
+static void pakfire_linter_file_free(struct pakfire_linter_file* lfile) {
+       if (lfile->linter)
+               pakfire_linter_unref(lfile->linter);
+       if (lfile->file)
+               pakfire_file_unref(lfile->file);
+       if (lfile->ctx)
+               pakfire_ctx_unref(lfile->ctx);
+       if (lfile->fd >= 0)
+               close(lfile->fd);
+}
+
+struct pakfire_linter_file* pakfire_linter_file_ref(struct pakfire_linter_file* lfile) {
+       ++lfile->nrefs;
+
+       return lfile;
+}
+
+struct pakfire_linter_file* pakfire_linter_file_unref(struct pakfire_linter_file* lfile) {
+       if (--lfile->nrefs > 0)
+               return lfile;
+
+       pakfire_linter_file_free(lfile);
+       return NULL;
+}
 
 #include <pakfire/fhs.h>
 #include <pakfire/file.h>
 #include <pakfire/linter.h>
+#include <pakfire/linter-file.h>
 #include <pakfire/logging.h>
 #include <pakfire/package.h>
 #include <pakfire/pakfire.h>
 
 static int pakfire_linter_payload(
                struct pakfire_linter* linter, struct pakfire_file* file, struct archive* a) {
+       struct pakfire_linter_file* lfile = NULL;
        int fd = -EBADF;
        int r;
 
        if (r < 0)
                goto ERROR;
 
+       // Create a linter file
+       r = pakfire_linter_file_create(&lfile, linter->ctx, linter, file, fd);
+       if (r < 0) {
+               ERROR(linter->ctx, "Could not create linter file for %s: %s\n", path, strerror(-r));
+               goto ERROR;
+       }
+
+       // XXX TODO
+
        // Check ELF files
        if (pakfire_linter_file_is_elf(linter, file, fd)) {
                // Check PIE
        }
 
 ERROR:
+       if (lfile)
+               pakfire_linter_file_unref(lfile);
+       if (fd >= 0)
+               close(fd);
+
        return r;
 }