]> git.ipfire.org Git - pakfire.git/commitdiff
ELF: Store the path
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 1 Jan 2025 16:25:20 +0000 (16:25 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 1 Jan 2025 16:25:20 +0000 (16:25 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/elf.c
src/libpakfire/include/pakfire/elf.h

index cb41c4718f7c381dfb096e1cc7fc2c05e0fb65cc..1f58f9af9f0546039d85ec3d2d0ef33464a76f46 100644 (file)
 #############################################################################*/
 
 #include <errno.h>
+#include <stdlib.h>
 
 #include <pakfire/ctx.h>
 #include <pakfire/elf.h>
+#include <pakfire/string.h>
 
 // libelf
 #include <gelf.h>
@@ -31,6 +33,9 @@ struct pakfire_elf {
        struct pakfire_ctx* ctx;
        int nrefs;
 
+       // Path
+       char path[PATH_MAX];
+
        // File Descriptor
        int fd;
 
@@ -58,7 +63,8 @@ static void pakfire_elf_free(struct pakfire_elf* self) {
        free(self);
 }
 
-int pakfire_elf_open(struct pakfire_elf** elf, struct pakfire_ctx* ctx, int fd) {
+int pakfire_elf_open(struct pakfire_elf** elf,
+               struct pakfire_ctx* ctx, const char* path, int fd) {
        struct pakfire_elf* self = NULL;
        int r;
 
@@ -77,6 +83,11 @@ int pakfire_elf_open(struct pakfire_elf** elf, struct pakfire_ctx* ctx, int fd)
        // Initialize the reference counter
        self->nrefs = 1;
 
+       // Store the path
+       r = pakfire_string_set(self->path, path);
+       if (r < 0)
+               goto ERROR;
+
        // Store the file descriptor
        self->fd = dup(fd);
        if (self->fd < 0) {
@@ -122,3 +133,7 @@ struct pakfire_elf* pakfire_elf_unref(struct pakfire_elf* self) {
        pakfire_elf_free(self);
        return NULL;
 }
+
+const char* pakfire_elf_path(struct pakfire_elf* self) {
+       return self->path;
+}
index 7d5a55e510d8dbac5b1f1af1ddf65c375fa00e16..7a04a6f25083b5de89f80f27a96ca7bc86387950 100644 (file)
@@ -28,11 +28,14 @@ struct pakfire_elf;
 
 #include <pakfire/ctx.h>
 
-int pakfire_elf_open(struct pakfire_elf** elf, struct pakfire_ctx* ctx, int fd);
+int pakfire_elf_open(struct pakfire_elf** elf,
+       struct pakfire_ctx* ctx, const char* path, int fd);
 
 struct pakfire_elf* pakfire_elf_ref(struct pakfire_elf* self);
 struct pakfire_elf* pakfire_elf_unref(struct pakfire_elf* self);
 
+const char* pakfire_elf_path(struct pakfire_elf* self);
+
 #endif /* PAKFIRE_PRIVATE */
 
 #endif /* PAKFIRE_ELF_H */